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.

The Cache DefaultAbsoluteExpireTime property work only once

See original GitHub issue

Hi suppose cache config is

Configuration.Caching.Configure(CacheNames._roles, cache =>
{
            cache.DefaultAbsoluteExpireTime = DateTimeOffset.Now.AddMinutes(1);
});

and laod method is

public async Task<GetUsersToTestCacheOutput> GetUsersToTestCache(GetUsersToTestCacheInput input)
        {
            string cachKey = AbpSession.UserId.Value.ToString();
            var output = new GetUsersToTestCacheOutput();
            bool loadedFromCache = true;
            output.Data = await CacheManager.GetCache<string, List<NameValueDto>>(CacheNames._roles).GetAsync(cachKey, async () =>
            {
                loadedFromCache = false;
                var d = await (from p in _userRepo.GetAll()
                               select new
                               {
                                   p.Id,
                                   p.UserName
                               }).ToListAsync();
                return d.Select(p => new NameValueDto(p.UserName, p.Id.ToString())).ToList();
            });
            Logger.Info("load data for key " + cachKey + " from " + (loadedFromCache ? "cache" : "DB"));

            output.LoadedFromCache = loadedFromCache;
            return output;
        }

first call at 2022-10-30 10:48:40.803 (data fetched from DB) second call at 2022-10-30 10:49:34.157 (data fetched from cache) third call at 2022-10-30 10:49:34.877 (data fetched from DB) up to this point caching system is working properly forth call at 2022-10-30 10:49:35.247 (data fetch from DB) After that, every request is sent to the method, the information will be fetched from the database.

you can reproduce this step in https://github.com/Omital/TCache and execute TChache.TestConsole project.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
malimingcommented, Oct 31, 2022

This can be seen as design.

0reactions
Omitalcommented, Oct 31, 2022

hi @maliming Thank you, It work with

Configuration.Caching.Configure(CacheNames._roles, cache =>
           {
               cache.DefaultAbsoluteExpireTimeFactory = _ => DateTimeOffset.Now + TimeSpan.FromMinutes(1);
           });

but what about DefaultAbsoluteExpireTime? it has no functionality?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making sure (distributed) caches only store the latest value ...
Hi. · Well, putting the cache aside, if you have two people updating the same entity simultaneously with different values - which one...
Read more >
AbpCache sliding/absolute expire time · Issue #5390
Abp Memory Cache creates an absolute expire time using TimeSpan absoluteExpireTime relative to the current time, See.
Read more >
Releases · aspnetboilerplate/aspnetboilerplate
TargetNotifiers needs to be virtual in order for NHibernate to proxy it; ISSUE #6492: Bug: The Cache DefaultAbsoluteExpireTime property work only once ...
Read more >
Application Data Caching
If several concurrent invocations try to retrieve a cache value from the same missing key, the method will only be invoked once.
Read more >
Hybrid Caching unusual amount of redis cache hits #11060
It caches items requested from redis per request. In every request it will be cached locally. When the cache changed in the current...
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