Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache not working #654

Open
banitt opened this issue Feb 25, 2020 · 4 comments
Open

Cache not working #654

banitt opened this issue Feb 25, 2020 · 4 comments

Comments

@banitt
Copy link

banitt commented Feb 25, 2020

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.

@xXLAOKOONXx
Copy link
Contributor

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

_slidingTimes[key].Viewed();

Code inside .Viewed()
_expireAt = DateTime.Now.Add(_relativeExpiry);

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?

@banitt
Copy link
Author

banitt commented Feb 25, 2020

@xXLAOKOONXx
Oh, I thought item should be available up to 100 milliseconds.

@xXLAOKOONXx
Copy link
Contributor

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?

@BenFradet
Copy link
Owner

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants