November Happy Hour will be moved to Thursday December 5th.

Caching

Vote:
 

Ref caching documented here:

Is there a smart way of invalidating the cache?

#73738
Aug 07, 2013 13:38
Vote:
 

You can supply a cache dependency to the method in which you can do pretty much anything you'd like. If you're using GetContentResult the automatic caching does that using a dependency that "fires" whenever EPiServer's master cache key is updated.

#73740
Aug 07, 2013 14:18
Vote:
 

Here's the thing: I'm caching all product queries for 10 minutes, but I want to be able to "clear the cache". So my plan was to use a cache dependency and then create a plugin where an admin editor can "reset cache" by changing the dependency.

Keeping in mind that the cache dependency will be evaluated everytime the query runs, what would be the best way of implenting the cache dependency? I'm concerned that the cost of evaluating the cache dependency will be the same as the benefit from caching... if you see what I'm saying.

#73752
Aug 08, 2013 8:24
Vote:
 

Given that I'm not misunderstanding you I think you could do:

1. Create a constant string somewhere that is used as a cache key below. Let's say it's in a class named Banana with property name Key.

2. When querying do:

 2.1 Cache.Add(Banana.Key, "I'm a string whos value doesn't matter, to bad for me."); (Vital to use Cache.Add and not Cache.Insert)

 2.2. Execute the query with a dependency that monitors Banana.Key (using this constructor).

3. When editor presses "reset cache" do EPiServer.CacheManager.Remove(Banana.Key)

 

Note that Cache.Add doesn't modify the cache if the key already exist meaning that it will only be added after the application has just started or an editor has pressed "reset cached". By using EPiServer's cache manager when removing you'll clear the value on all servers meaning the query's cache will be cleared on all servers.

#73753
Edited, Aug 08, 2013 8:41
Vote:
 

The link in 2.2 to the CacheDependency constructor - can you explain the use of the datetime parameter?

#73758
Aug 08, 2013 11:03
Vote:
 

No :) This looks better :)

#73760
Aug 08, 2013 11:10
Vote:
 

Great, thanks! :)

#73761
Aug 08, 2013 11:34
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.