Interface ICacheSpecs
Cache Specs contain the definition of what the cached data should depend on, how long it should be cached and how the cache key should be generated. It uses a fluent API to continue adding rules / expirations / dependencies. Internally this is then used to create a cache policy.
[PublicApi]
public interface ICacheSpecs
Remarks
- Introduced as experimental in v17.09
- Released in 19.01
Methods
SetAbsoluteExpiration(DateTimeOffset)
Set absolute expiration, alternative is sliding expiration. If neither are set, a sliding expiration of 1 hour will be used.
ICacheSpecs SetAbsoluteExpiration(DateTimeOffset absoluteExpiration)
Parameters
absoluteExpirationDateTimeOffset
Returns
Remarks
If neither absolute nor sliding are set, a sliding expiration of 1 hour will be used. Setting both is invalid and will throw an exception.
SetSlidingExpiration(TimeSpan)
Set sliding expiration, alternative is absolute expiration.
ICacheSpecs SetSlidingExpiration(TimeSpan slidingExpiration)
Parameters
slidingExpirationTimeSpan
Returns
Remarks
If neither absolute nor sliding are set, a sliding expiration of 1 hour will be used. Setting both is invalid and will throw an exception.
VaryBy(string, int)
Vary the cache by a specific name and value. All cache items where this value is the same, will be considered the same. For example, this could be a category name or something where the data for this category is always the same.
ICacheSpecs VaryBy(string name, int value)
Parameters
Returns
VaryBy(string, string, NoParamOrder, bool)
Vary the cache by a specific name and value. All cache items where this value is the same, will be considered the same. For example, this could be a category name or something where the data for this category is always the same.
ICacheSpecs VaryBy(string name, string value, NoParamOrder protector = default, bool caseSensitive = false)
Parameters
namestringvaluestringprotectorNoParamOrdercaseSensitivebool
Returns
VaryByModule()
Vary the cache by the current module, so that each module has its own cache.
ICacheSpecs VaryByModule()
Returns
VaryByModule(int)
Vary the cache by module, so that each module has its own cache.
ICacheSpecs VaryByModule(int id)
Parameters
idintModule id to use
Returns
VaryByPage()
Vary the cache by the current page, so that each page has its own cache.
ICacheSpecs VaryByPage()
Returns
VaryByPage(int)
Vary the cache by page, so that each page has its own cache. By default, it will take the current page, but you can optionally specify a custom page or ID.
ICacheSpecs VaryByPage(int id)
Parameters
idintpage id to use
Returns
VaryByPageParameters(string, NoParamOrder, bool)
Vary the cache by one or more specific page parameter, like ?category=1 or ?category=1&sort=asc.
Using this method will only vary the cache by the mentioned parameters and ignore the rest.
ICacheSpecs VaryByPageParameters(string names = null, NoParamOrder protector = default, bool caseSensitive = false)
Parameters
namesstringNames of one or more parameters, comma-separated. If null, all parameters are used, if
"", no parameters are used.protectorNoParamOrdercaseSensitiveboolDetermines if the value should be treated case-sensitive, default is
false
Returns
VaryByParameters(IParameters, NoParamOrder, string, bool)
Vary the cache by a custom parameters list.
ICacheSpecs VaryByParameters(IParameters parameters, NoParamOrder protector = default, string names = null, bool caseSensitive = false)
Parameters
parametersIParametersparameters object
protectorNoParamOrdernamesstringNames of one or more parameters, comma-separated
caseSensitiveboolDetermines if the value should be treated case-sensitive, default is
false
Returns
VaryByUser()
Vary the cache by current user, so that each user has its own cache.
ICacheSpecs VaryByUser()
Returns
VaryByUser(int)
Vary the cache by user, so that each user has its own cache.
ICacheSpecs VaryByUser(int id)
Parameters
idintUser id to use
Returns
WatchAppData(NoParamOrder)
Depend on the app data, so if any data changes, the cache will be invalidated.
ICacheSpecs WatchAppData(NoParamOrder protector = default)
Parameters
protectorNoParamOrder
Returns
WatchAppFolder(NoParamOrder, bool?)
Depend on the app folder, so if any file in the app folder changes, the cache will be invalidated. WIP!
ICacheSpecs WatchAppFolder(NoParamOrder protector = default, bool? withSubfolders = null)
Parameters
protectorNoParamOrderwithSubfoldersbool?should it also watch subfolders? default is
true