feat: add cache control in response
This commit is contained in:
26
Endpoint/Common/Attributes/CacheMaxAgeAttribute.cs
Normal file
26
Endpoint/Common/Attributes/CacheMaxAgeAttribute.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Common.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
public class CacheMaxAgeAttribute : Attribute
|
||||
{
|
||||
public int MaxAge { get; }
|
||||
|
||||
public CacheMaxAgeAttribute(int days = 0, int hours = 0, int minutes = 0)
|
||||
{
|
||||
MaxAge = (int)new TimeSpan(days, hours, minutes, 0).TotalSeconds;
|
||||
}
|
||||
|
||||
public CacheMaxAgeAttribute(int minutes) : this(0, 0, minutes)
|
||||
{
|
||||
}
|
||||
|
||||
public CacheMaxAgeAttribute(bool usingSetting = false)
|
||||
{
|
||||
if (usingSetting)
|
||||
MaxAge = -1;
|
||||
else
|
||||
MaxAge = 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user