Class Extensions
Extensions methods to make it easier to work with the distributed cache
Inheritance
Namespace: PnP.Framework.Modernization.Cache
Assembly: PnP.Framework.dll
Syntax
public static class Extensions : object
Methods
FromByteArray<T>(Byte[])
Converts a byte array to an object
Declaration
public static T FromByteArray<T>(this byte[] byteArray)
where T : class
Parameters
System.Byte[]
byteArray
Byte array |
Returns
T
Object |
Type Parameters
T
Type of the object to return |
Get<T>(IDistributedCache, String)
Gets an object from the connected cache system
Declaration
public static T Get<T>(this IDistributedCache distributedCache, string key)
where T : class
Parameters
IDistributedCache
distributedCache
Connected cache system |
System.String
key
Key of the object in the cache |
Returns
T
Object of the type T |
Type Parameters
T
Type of the object to return from cache |
GetAndInitialize<T>(IDistributedCache, String)
Gets an object from the connected cache system. If not cached the object will be created
Declaration
public static T GetAndInitialize<T>(this IDistributedCache distributedCache, string key)
where T : class, new()
Parameters
IDistributedCache
distributedCache
Connected cache system |
System.String
key
Key of the object in the cache |
Returns
T
Object of the type T |
Type Parameters
T
Type of the object to return from cache |
GetAsync<T>(IDistributedCache, String)
Gets an object from the connected cache system
Declaration
public static async Task<T> GetAsync<T>(this IDistributedCache distributedCache, string key)
where T : class
Parameters
IDistributedCache
distributedCache
Connected cache system |
System.String
key
Key of the object in the cache |
Returns
Task<T>
Object of the type T |
Type Parameters
T
Type of the object to return from cache |
Set<T>(IDistributedCache, String, T, DistributedCacheEntryOptions)
Sets an object of type T in connected cache system
Declaration
public static void Set<T>(this IDistributedCache distributedCache, string key, T value, DistributedCacheEntryOptions options)
where T : class
Parameters
IDistributedCache
distributedCache
Connected cache system |
System.String
key
Key of the object in the cache |
T
value
Value to be cached |
DistributedCacheEntryOptions
options
Caching options |
Type Parameters
T
Type of the object to cache |
SetAsync<T>(IDistributedCache, String, T, DistributedCacheEntryOptions, CancellationToken)
Sets an object of type T in connected cache system
Declaration
public static async Task SetAsync<T>(this IDistributedCache distributedCache, string key, T value, DistributedCacheEntryOptions options, CancellationToken token = null)
where T : class
Parameters
IDistributedCache
distributedCache
Connected cache system |
System.String
key
Key of the object in the cache |
T
value
Value to be cached |
DistributedCacheEntryOptions
options
Caching options |
CancellationToken
token
Cancellation token |
Returns
Task
|
Type Parameters
T
Type of the object to cache |
ToByteArray(Object)
Converts an object into a bytearray
Declaration
public static byte[] ToByteArray(this object obj)
Parameters
System.Object
obj
Object to return as byte array |
Returns
System.Byte[]
byte array |