PerRequestCacheManager Issue

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I'm developing a plugin and noticed some odd behavior with the PerRequestCacheManager.  While doing some testing I realized that it has the same behavior in the base application services which makes me think I'm perhaps misunderstanding it.


For example:

(Using stock nopCommerce install with default data)

URL:/admin/Topic/Edit/1

The TopicService calls:

return _cacheManager.Get(key, () => _topicRepository.GetById(topicId));


The PerRequestCacheManager is called and I would expect it to have to query the database the first time and then cache it.  Even on subsequent calls of the same URL though it is not returning a cached value.  The code below seems to always be skipped as the key does not already exist in cache:

                
//item already is in cache, so return it
if (items[key] != null)
return (T)items[key];


What am I missing?
4 years ago
You should use IStaticCacheManager to get value from cache on subsequent calls.
4 years ago
Thanks for the response.  Isn't IStaticCacheManager for long-term caching and ICacheManager for short term?  When I step through the TopicService it queries the database each time.  Another example is the CountryService.  It uses ICacheManager and every time you load the countries (/Admin/Country/List) the database gets queried rather than pulling from cache.
4 years ago
IStaticCacheManager is long term caching
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.