Dofactory.com
Dofactory.com
 Back to list
Views:   7.4K
Replies:  1
Archived

Spark 4.5: How to update or refresh the cache?

Are there any examples as to how I should update the cache if a new artist is added from the MVC layer? What if I expose a web api method that allows an artist to be inserted into the database, how do I then refresh the cache on MVC layer? Do I move the ArtCache.cs from the MVC project into the Domain layer?
Parity Bit, Sep 25, 2013
Reply 1
Parity Bit: 

Good question.

Once a change is made (for example an Artist is updated or a new Artist is added) you have these options: 

  1. Manually add the new Artist to the Cache or update the one already in cache, or 
  2. Clear the entire Artist cache. (You will find a ClearArtists method in the ArtCache that handles this for you)

The last method is the simplest and also the preferred way. Note that the cache will refill automatically through the lazy loading mechanism. 

The first method should only be used if your cache is very large and/or frequent updates take place (essentially you want to avoid frequent large database selects).  If you choose to use method 1. then remember to place locks around the critical code to maintain thread safety. 

By the way: you can add the extra code that interacts with the cache in your code behind or (even better) in the service layer. 
There is no need move it to the Domain project because caching here is rather application specific. (I would only move it to the Domain project if caching were a cross-cutting concern in which you wish to automatically cache just about all tables. In that case there are probably better 3rd party solutions to do that). 

Hope this helps. 
Jack Poorte



Jack Poorte, Sep 26, 2013
Thanks for taking the time to reply but I still don't know what the design has to do with cloud? What makes this app "portable" to the could? The n-tier design or the actual service? Thanks
Jul 25, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.