C
C#3y ago
kopuo

ResponseCache duration in minutes instead seconds

Can I set or convert values from seconds to minutes for the [ResponseCache (Duration = 3600)] attribute? I would like to eventually save something like [ResponseCache (Duration = 60)] where 60 is minutes.
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
kopuo
kopuoOP3y ago
It's a fact, thanks. Another solution that can be used in such a situation is to create a CacheProfile in Program.cs:
builder.Services.AddControllers(options =>
{
options.CacheProfiles.Add("Cache60Mins",
new CacheProfile()
{
Duration = 60 * 60, // minutes * seconds
Location = ResponseCacheLocation.Any
});
});
builder.Services.AddControllers(options =>
{
options.CacheProfiles.Add("Cache60Mins",
new CacheProfile()
{
Duration = 60 * 60, // minutes * seconds
Location = ResponseCacheLocation.Any
});
});
Use:
[ResponseCache(CacheProfile = "Cache60Mins")]
//method
[ResponseCache(CacheProfile = "Cache60Mins")]
//method
This solution is useful when we want to use the settings in minutes from appsettings
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server