RiotSharp
RiotSharp copied to clipboard
Cache not working
In this example
var cache = new Cache();
cache.Add("data", "test", TimeSpan.FromMilliseconds(100));
while(true)
{
var item = cache.Get<string,string>("data");
Console.WriteLine(item.ToString());
}
item in cache should be available for 100 milliseconds, but instead it is always available.
I am not that confident in this caching. I found a code snipped that refreshes the expiry duration every time you access it:
Call of .Viewed() inside the Get function https://github.com/BenFradet/RiotSharp/blob/7ae756c8ce7eb1c700739f85f8b5fc8fd8521723/RiotSharp/Caching/Cache.cs#L51 Code inside .Viewed() https://github.com/BenFradet/RiotSharp/blob/7ae756c8ce7eb1c700739f85f8b5fc8fd8521723/RiotSharp/Caching/Cache.cs#L282
This behavior makes kinda sense, so I guess it is intended. @banitt may you check if caching works if you delay for a second before accessing the data in an endless loop?
@xXLaokoonXx Oh, I thought item should be available up to 100 milliseconds.
FileCache works as you expect it to work. As Cache and FileCache claim to do the same with different backend implementation it might be a good point to align both approaches regarding expiry. In the same change Cache could implement CacheData. @JanOuborny or @BenFradet your thoughts?
As Cache and FileCache claim to do the same with different backend implementation it might be a good point to align both approaches regarding expiry.
agreed :+1: