Class InMemoryBlobCache
- Namespace
- Akavache
- Assembly
- Akavache.Core.dll
This class is an IBlobCache backed by a simple in-memory Dictionary. Use it for testing / mocking purposes.
public class InMemoryBlobCache : ISecureBlobCache, IObjectBlobCache, IBlobCache, IDisposable, IEnableLogger
- Inheritance
-
In
Memory Blob Cache
- Implements
- Extension Methods
Constructors
InMemoryBlobCache()
Initializes a new instance of the In
InMemoryBlobCache(IEnumerable<KeyValuePair<string, byte[]>>)
Initializes a new instance of the In
Parameters
initialContents
IEnumerable<KeyValue <string, byte[]>>Pair The initial contents of the cache.
InMemoryBlobCache(IScheduler)
Initializes a new instance of the In
Parameters
scheduler
ISchedulerThe scheduler to use for Observable based operations.
InMemoryBlobCache(IScheduler?, IEnumerable<KeyValuePair<string, byte[]>>?)
Initializes a new instance of the In
public InMemoryBlobCache(IScheduler? scheduler, IEnumerable<KeyValuePair<string, byte[]>>? initialContents)
Parameters
scheduler
ISchedulerThe scheduler to use for Observable based operations.
initialContents
IEnumerable<KeyValue <string, byte[]>>Pair The initial contents of the cache.
Properties
ForcedDateTimeKind
Gets or sets the DateTimeKind handling for BSON readers to be forced.
Property Value
Remarks
By default, Newtonsoft.DateTimeKind
, you can set this value.
Scheduler
Gets the IScheduler used to defer operations. By default, this is BlobCache.TaskpoolScheduler.
Property Value
- IScheduler
Shutdown
Gets an Observable that fires after the Dispose completes successfully, since there is no such thing as an AsyncDispose().
Property Value
- IObservable<Unit>
Methods
Dispose()
Dispose(bool)
Disposes of the managed memory inside the class.
Parameters
isDisposing
boolIf this is being called by the Dispose method.
Flush()
This method guarantees that all in-flight inserts have completed and any indexes have been written to disk.
Returns
- IObservable<Unit>
A signal indicating when the flush is complete.
Get(string)
Retrieve a value from the key-value cache. If the key is not in the cache, this method should return an IObservable which OnError's with KeyNotFoundException.
Parameters
key
stringThe key to return asynchronously.
Returns
- IObservable<byte[]>
A Future result representing the byte data.
GetAllKeys()
Return all keys in the cache. Note that this method is normally for diagnostic / testing purposes, and that it is not guaranteed to be accurate with respect to in-flight requests.
Returns
- IObservable<IEnumerable<string>>
A list of valid keys for the cache.
GetAllObjects<T>()
Return all objects of a specific Type in the cache.
Returns
- IObservable<IEnumerable<T>>
A Future result representing all objects in the cache with the specified Type.
Type Parameters
T
The type of object associated with the blob.
GetCreatedAt(string)
Returns the time that the key was added to the cache, or returns null if the key isn't in the cache.
Parameters
key
stringThe key to return the date for.
Returns
- IObservable<Date
Time ?>Offset The date the key was created on.
GetObjectCreatedAt<T>(string)
Returns the time that the object with the key was added to the cache, or returns null if the key isn't in the cache.
Parameters
key
stringThe key to return the date for.
Returns
- IObservable<Date
Time ?>Offset The date the key was created on.
Type Parameters
T
The type of object associated with the blob.
GetObject<T>(string)
Get an object from the cache and deserialize it via the JSON serializer.
Parameters
key
stringThe key to look up in the cache.
Returns
- IObservable<T>
A Future result representing the object in the cache.
Type Parameters
T
The type of object associated with the blob.
Insert(string, byte[], DateTimeOffset?)
Insert a blob into the cache with the specified key and expiration date.
Parameters
key
stringThe key to use for the data.
data
byte[]The data to save in the cache.
absoluteExpiration
DateTime ?Offset An optional expiration date. After the specified date, the key-value pair should be removed.
Returns
- IObservable<Unit>
A signal to indicate when the key has been inserted.
InsertObject<T>(string, T, DateTimeOffset?)
Insert an object into the cache, via the JSON serializer.
public IObservable<Unit> InsertObject<T>(string key, T value, DateTimeOffset? absoluteExpiration = null)
Parameters
key
stringThe key to associate with the object.
value
TThe object to serialize.
absoluteExpiration
DateTime ?Offset An optional expiration date.
Returns
- IObservable<Unit>
A Future result representing the completion of the insert.
Type Parameters
T
The type of object associated with the blob.
Invalidate(string)
Remove a key from the cache. If the key doesn't exist, this method should do nothing and return (not throw KeyNotFoundException).
Parameters
key
stringThe key to remove from the cache.
Returns
- IObservable<Unit>
A signal indicating when the invalidate is complete.
InvalidateAll()
Invalidate all entries in the cache (i.e. clear it). Note that this method is blocking and incurs a significant performance penalty if used while the cache is being used on other threads.
Returns
- IObservable<Unit>
A signal indicating when the invalidate is complete.
InvalidateAllObjects<T>()
Invalidates all objects of the specified type. To invalidate all objects regardless of type, use InvalidateAll.
Returns
- IObservable<Unit>
A Future result representing the completion of the invalidation.
Type Parameters
T
The type of object associated with the blob.
InvalidateObject<T>(string)
Invalidates a single object from the cache. It is important that the Type Parameter for this method be correct, and you cannot use IBlobCache.Invalidate to perform the same task.
Parameters
key
stringThe key to invalidate.
Returns
- IObservable<Unit>
A Future result representing the completion of the invalidation.
Type Parameters
T
The type of object associated with the blob.
OverrideGlobals(IDictionary<string, byte[]>, IScheduler?)
Overrides the global registrations with specified values.
public static InMemoryBlobCache OverrideGlobals(IDictionary<string, byte[]> initialContents, IScheduler? scheduler = null)
Parameters
initialContents
IDictionary<string, byte[]>The default inner contents to use.
scheduler
ISchedulerThe default scheduler to use.
Returns
- In
Memory Blob Cache A generated cache.
OverrideGlobals(IDictionary<string, object>, IScheduler?)
Overrides the global registrations with specified values.
public static InMemoryBlobCache OverrideGlobals(IDictionary<string, object> initialContents, IScheduler? scheduler = null)
Parameters
initialContents
IDictionary<string, object>The default inner contents to use.
scheduler
ISchedulerThe default scheduler to use.
Returns
- In
Memory Blob Cache A generated cache.
OverrideGlobals(IScheduler?, params KeyValuePair<string, byte[]>[])
Overrides the global registrations with specified values.
public static InMemoryBlobCache OverrideGlobals(IScheduler? scheduler = null, params KeyValuePair<string, byte[]>[] initialContents)
Parameters
scheduler
ISchedulerThe default scheduler to use.
initialContents
KeyValue <string, byte[]>[]Pair The default inner contents to use.
Returns
- In
Memory Blob Cache A generated cache.
Vacuum()
This method eagerly removes all expired keys from the blob cache, as well as does any cleanup operations that makes sense (Hint: on SQLite3 it does a Vacuum).
Returns
- IObservable<Unit>
A signal indicating when the operation is complete.