Обновляйте sh кэшированные данные каждую неделю в часовом поясе воскресенья EST по указанному c времени в. Net Core 2.2 - PullRequest
0 голосов
/ 21 апреля 2020

Попытка установить срок действия кэша для каждой недели по часовому поясу воскресенья EST в указанное время c. Я могу установить срок действия для каждого часа, но не могу установить срок действия для каждой недели.


Я добавил кэш In-Memory в startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMemoryCache();
    }

И мой кеш менеджер класса

public class CacheManager
{
    private IMemoryCache _cache;

    public CacheManager(IMemoryCache memoryCache)
    {
        _cache = memoryCache;
    }

    public string CacheTryGetValueSet()
    {
        string cacheEntry;

        // Look for cache key.
        if (!_cache.TryGetValue(CacheKeys.ApiData, out cacheEntry))
        {
            // Key not in cache, so get data.
            cacheEntry = string.Empty; // will assign the api data in future.



            // Set cache options.
            var cacheEntryOptions = new MemoryCacheEntryOptions()
                .SetAbsoluteExpiration(TimeSpan.FromHours(1))// I need this configuration to expiry on every week sunday at specific time on EST Time Zone.
                 .RegisterPostEvictionCallback((key, value, reason, state) => {  /*  will refresh the api data  once cache expires*/ });



            // Save data in cache.
            _cache.Set(CacheKeys.ApiData, cacheEntry,cacheEntryOptions);
        }

        return cacheEntry.ToString();
    }

}

public static class CacheKeys
{
    public static string ApiData { get { return "_ApiData"; } }
}
...