question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RedisRemoteEvictionExtension evicts key on SetAsync

See original GitHub issue

Hi,

Thanks for the great library.

Maybe I’m missing something but I have come across an issue that is confusing me:

Consider:

var layers = new ICacheLayer[]
                {
                    new RedisCacheLayer(cacheLayerMultiplexer, databaseIndex: 1),
                };

var myCacheStack = new CacheStack(
                layers,
                new ICacheExtension[]
                    {
                        new RedisRemoteEvictionExtension(
                            cacheLayerMultiplexer,
                            new ICacheLayer[]{})),    // Do not evict any layers for this example
                    });

// Add something to cache stack
await myCacheStack.SetAsync("hello:world", 123, TimeSpan.FromMinutes(5));

// Check redis, no key found

var result = await myCacheStack.GetAsync<int>("hello:world");

if (result == null)
{
      Console.WriteLine("No cache entry");
}

I wasn’t sure on the setup, originally I also had a MemoryCacheLayer as well, and I figured you would pass layersToEvict as:

layersToEvict = layers.Where(x => x.GetType() != typeof(RedisCacheLayer)).ToArray();

And pass this into the RedisRemoteEvictionExtension - however, whatever method I use to configure this extension, it seems to evict the key I add to redis, from redis, the moment its added.

Let me know if I have misunderstood something here! Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
mgoodfellowcommented, Apr 22, 2021

That would be perfect. This then enables any IoC container to be implemented in conjunction with this library. You managed to describe it a lot more succinctly than I did, I think I need another coffee in the morning before trying to outline an idea 😃

1reaction
Turnerjcommented, Jun 27, 2022

Forgot to close this one - with v0.12.0, there is now specific ILocalCacheLayer and IDistributedCacheLayer interfaces and the RedisRemoteEvictionExtension now asks the CacheStack for the cache layers (rather than specifying them yourself), specifically looking for ILocalCacheLayer instances only. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

GetOrSetAsync fails to write value to redis when any ...
I'm trying a basic redis backed setup. SetAsync works, but GetOrSetAsync is not setting the value into redis. It is setting the value...
Read more >
Key eviction
Overview of Redis key eviction policies (LRU, LFU, etc.) When Redis is used as a cache, it is often convenient to let it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found