Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Steve Smith did two great blog posts which demonstrate how to use his CachedRepository pattern to achieve the result you're looking for.</p> <p><a href="http://ardalis.com/introducing-the-cachedrepository-pattern" rel="noreferrer"> Introducing the CachedRepository Pattern</a></p> <p><a href="http://ardalis.com/building-a-cachedrepository-via-strategy-pattern" rel="noreferrer">Building a CachedRepository via Strategy Pattern</a></p> <p>In these two posts he shows you how to set up this pattern and also explains why it is useful. By using this pattern you get caching without your existing code seeing any of the caching logic. Essentially you use the cached repository as if it were any other repository.</p> <pre><code>public class CachedAlbumRepository : IAlbumRepository { private readonly IAlbumRepository _albumRepository; public CachedAlbumRepository(IAlbumRepository albumRepository) { _albumRepository = albumRepository; } private static readonly object CacheLockObject = new object(); public IEnumerable&lt;Album&gt; GetTopSellingAlbums(int count) { Debug.Print("CachedAlbumRepository:GetTopSellingAlbums"); string cacheKey = "TopSellingAlbums-" + count; var result = HttpRuntime.Cache[cacheKey] as List&lt;Album&gt;; if (result == null) { lock (CacheLockObject) { result = HttpRuntime.Cache[cacheKey] as List&lt;Album&gt;; if (result == null) { result = _albumRepository.GetTopSellingAlbums(count).ToList(); HttpRuntime.Cache.Insert(cacheKey, result, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero); } } } return result; } } </code></pre>
    singulars
    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.
    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