Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To avoid hitting the database for each webpage request (generally an expensive operation), Object Caching (introduced in .NET 4.0) can be used. This would result in fast serving of webpages because everything would be handled directly from memory. Database operations would occur only if the data actually changed, or if the cache was evicted from memory due to resource constraints or your CacheItemPolicy settings.</p> <p>The practical strategy used in this case would be as follows.</p> <p>Step-1. In your Model method where data for the "id" row is being modified/added/deleted, complete that database operation and then:</p> <ul> <li>If your object already exists in the cache, evict it;</li> <li><a href="http://msdn.microsoft.com/en-us/library/dd780623.aspx" rel="noreferrer" title="Create a new cache entry">Create a new cache entry</a> for the object.</li> </ul> <p>Step-2. Retrieve the object from cache whenever possible, refreshing from the db only if necessary:</p> <ul> <li>From your Controller action method, call a Model method that returns the object identified by the "id" parameter;</li> <li>Within your Model method, check the cache for this id. If it is null, retrieve the data from your database and build the object as you would normally do, and then store the complete object in the cache;</li> <li>From the Model method, return the content of the cache (i.e. your specific object for this id) back to the calling Controller action method, and then let the action method populate and serve the View as usual.</li> </ul> <p>(The <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx" rel="noreferrer" title="MemoryCache">MemoryCache</a> class is the concrete implementation of the ObjectCache class).</p> <p>With this approach, the OutputCache on the Controller method would not need to be used at all, and the data caching decisions would all be fully encapsulated within the Model. We would get a cleaner separation of concerns; much higher efficiency, better response times, and improved scalability; and a reduced dependency on costly database operations.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload