Blog Logo
TAGS

Easy Way to Implement Second-Level Cache in Entity Framework

This article explains how to easily implement second-level caching in Entity Framework by adding an extension method for the IQueryable interface. Second-level caching is a technique that stores database query results in the application-level cache so they can be accessed more quickly on the subsequent request. This article provides the code for QueryCacheExtensions, contains FromCache() and FromCacheAsync() methods which store the query results in a memory cache so they can be reused on the same future request. The article also provides information about AbsoluteExpirationSeconds that is used to set how long the data stays in the cache.