5

I am trying to implement caching in ASP.Net core app. Currently What I have implemented is In Memory caching using IMemoryCache but what I want is cache should get invalidated if corresponding record in SQL server 2016 gets changed. One way I found it SQLCacheDependency but it is not a part of .Net Core as per this link

Any thoughts on this ?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
AnandSonake
  • 567
  • 1
  • 8
  • 19

2 Answers2

2

Right now this class hasn't been migrated to the .Net Core, so you can't easily manage out such logic. Probably it will be a part of .Net Standard 2.0, so you either implement some temporary solution with CancellationChangeToken with direct sql database checks (which is very inefficient) or wait for update.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
-1

You could add CancellationChangeToken and then call Cancel method on it, this should evict your record from the in-memory cache. On top of it, there is a PostEvictionDelegate callback available to you (to fire additional actions after the cache record has been evicted). You can read more here: https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory

Philip P.
  • 1,162
  • 1
  • 6
  • 15
  • How do you suggest to call cancel method? Create a polling for the sql database? – VMAtm Mar 19 '17 at 14:18
  • @VMAtm Well, polling is one way. Considering it's a cache, though, cache should be validated when the database is actually called (based on cache invalidation timeout and so on, unless it's critical to always validate it) - if cache is a miss then the cancel method is called as part of repository implementation. – Philip P. Mar 19 '17 at 20:36