jeudi 17 mai 2018

Best Design Patterns for editable Settings file

I'd like some direction on best methods and Patterns to apply to the following problem.

I have a web settings file that I want authenticated web site users to be able to view and edit. Users call a Web Api to View and Update the file.

The business rules are:

Rule 1. Multiple users can view file but only one user can edit file at a time.

Rule 2. If error occurs when editing/updating config file then previous one should be restored.

Rule 3. After a successful update the settings changes should be applied to web site.

My thoughts on this are:

Rule 1 - I persist the copy of the file to my database with aassociated timestamp (Proxy Pattern?).

When a User calls the Read API I supply the database version of the file or cached version?. When User wants to update a file I compare their timestamps, if equal I lock the physical file and apply the users edited file then I update the persisted copy in my database with a new Timestamp. Users should still be able to read the file while I have it locked.

Rule 2 - Whilst updating the file I catch any errors and Undo (Command or Memento Pattern) the changes by re-applying the copy I persisted to the database - then report failure to the user.

Rule 3 Call some event or similar to recache the settings file on the website.

Aucun commentaire:

Enregistrer un commentaire