Ticket (Solved)

Conditional caching?

When using ICacheManager, is there a way to decide whether the value that is returned should be cached or not?

eg:

            var result = _cacheManager.Get(cacheKey, ctx =>
            {
                ctx.Monitor(_signals.When(cacheKey));
                var x = _aService.DoSomething();
                if(x==null){
                    //don't cache
                }

                return x;
            }

Re: Conditional caching?

Interesting, I received the exact same question a few days ago. Until we can come up with a nice solution we simply trigger the signal right after the *_cacheManager.Get* call if the returned value is null. Alternatively, maybe you could implement an IVolatileToken, called NullToken for example, which sets its IsCurrent property to false if the cached value is null. That would cause the cache manager to immediately evict the cache entry.

Friday, May 16, 2014 12:58:32 PM bysfmskywalker

Re: Conditional caching?

I'm currently invalidating the cache immediately after setting it if the value is null, but I like the IVolatileToken idea much better. Thanks.

Friday, May 16, 2014 11:32:39 PM bychris
  • chris
  • Lv. 01 Rookie
  • Total EXP: 6

Post a reply

You need to be signed in to post a reply.

Sign In