Skip to content
Alastair Crabtree edited this page Feb 25, 2019 · 9 revisions

LazyCache 2 now depends on NetStandard 2.0 so you will need to migrate the rest of your app to that/netcore2 first.

  1. Upgrade app to netstandard2.0 or netcore2 or above

  2. Remove System.Runtime.Caching package/dependecy (We have moved to Microsoft.Extensions.Caching.Memory)

  3. Remove references to IAppCache.ObjectCache as Lazycache has changed to a cache provider model. To access the provider use IAppCache.CacheProvider instead.

  4. If using aspnet core or Microsoft.Extensions.DependecyInjection add package LazyCache.AspNetCore for easy dependency injection registration and add ServiceCollection.AddLazyCache() to your startup.cs;

  5. If not using Microsoft.Extensions.DependecyInjection then add package LazyCache 2.x or above.

  6. If not using DI the default constructor is no longer recommended. Change code the creates the cache to the following:

    IAppCache cache = new CachingService(CachingService.DefaultCacheProvider); 
    
  7. If using a different default cache period use the following to change the seconds in the cache, as it is no longer in the constructor

    IAppCache cache = new CachingService(CachingService.DefaultCacheProvider);
    cache.DefaultCachePolicy.DefaultCacheDurationSeconds = 60 * 3; //3mins
    
  8. Try and run your app, fix any compiler issues

  9. Fix compiler warnings - note we have changed from CacheItemPolicy to MemoryCacheEntryOptions. RemovedCallback is now PostEvictionCallbacks.