3

I am using FromCache() method whenever I need to retrieve data from cache.

I haven't set any default caching policy and am using whatever EF plus use by default.

What's the default cache duration? one minute? or infinite?

brian
  • 664
  • 6
  • 8
  • Looks like 5 minutes: https://github.com/zzzprojects/EntityFramework-Plus/issues/48 Though, you'd think this was easier to find. The default options are from QueryCacheManager, so perhaps you can inspect that at runtime or in the code if it is open source. –  Jan 15 '18 at 21:37
  • Thanks for the quick response. I will take a look at their source if they are open. – brian Jan 16 '18 at 12:51

2 Answers2

5

Disclaimer: I'm the owner of the project Entity Framework Plus

Entity Framework Plus use the MemoryCache by default. We don't override anything. See EF+ Memory Cache

So the question should be more What is the default .NET Memory Cache duration?

Looking on MSDN, it sounds that if nothing is provided, the default is InfiniteAbsoluteExpiration

If no eviction or expiration information is provided, the default is InfiniteAbsoluteExpiration, which means that items in the cache do not expire based on an absolute time. Instead, items expire only when there is memory pressure. As a best practice, you should always explicitly provide either an absolute or a siding expiration. In this walkthrough, you use an absolute expiration of 10 seconds.

Jonathan Magnan
  • 10,874
  • 2
  • 38
  • 60
  • 1
    Thank you. I will add an explicit expiration for the cache. It will be great for others if this explanation is added to your guide. BTW, we love the EF Plus. It is very helpful filling in some missing features in EF. I really appreciate your effort. – brian Jan 16 '18 at 15:05
0

See answer above but you can use this to set default policy:

var options = new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromHours(2)};
QueryCacheManager.DefaultMemoryCacheEntryOptions = options;

Source: https://entityframework-plus.net/ef-core-query-cache#expiration

bobt
  • 411
  • 3
  • 8