How do I cache a complex object created in ASP.NET MVC?

I am creating a website so that users can create a schedule with multiple tasks. The schedule and task information is stored in the database.

When creating a schedule, the user can add, edit or delete as many tasks as they want before finally saving the schedule. These changes are saved in the database so that the user can resume editing at a later point (if their session ends unexpectedly or is interrupted).

Each time a request is received to update a task, the website calls the appropriate method from its data access layer, then re-requests the entire schedule data object from the database to display to the user.

This seems overkill when only the job is being edited. I want to cache a schedule object and its list of tasks in the HttpContext.Session and only update the individual task (or the schedule object when it changes).

Are there any dangers when my two versions get out of sync if I only update my cached object when I get confirmation that the edit operation was successful?

+3


source to share


2 answers


If the session is reset, which can be caused by things like updating the web.config, modifying the DLLs, even the automatic disposal of the IIS application pool, it will clean up your sessions. If you have multiple web servers, you have to worry about synchronizing sessions across multiple web servers and one of them. Personally, I try not to store anything in the session where it can be avoided.



0


source


Are there any dangers when two versions get out of sync

As long as you delete the new state from the server after successfully editing and updating the cache, then there should be no problem.



One thing to keep in mind: if you are going to enable co-authoring, you will need to enter a poll so that your local copy is not out of date. However, from your description, this does not seem likely.

0


source







All Articles