Table of Contents

Class InMemoryBlobCacheBase

Namespace
Akavache
Assembly
Akavache.dll

Base class for in-memory blob cache implementations that provides common functionality for all serialization-specific InMemoryBlobCache implementations.

public abstract class InMemoryBlobCacheBase : ISecureBlobCache, IBlobCache, IDisposable, IAsyncDisposable
Inheritance
InMemoryBlobCacheBase
Implements
Derived
Extension Methods
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>)
WhenAnyMixin.WhenAny<TSender, TRet, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(TSender?, Expression<Func<TSender, T1>>, Expression<Func<TSender, T2>>, Expression<Func<TSender, T3>>, Expression<Func<TSender, T4>>, Expression<Func<TSender, T5>>, Expression<Func<TSender, T6>>, Expression<Func<TSender, T7>>, Expression<Func<TSender, T8>>, Expression<Func<TSender, T9>>, Expression<Func<TSender, T10>>, Expression<Func<TSender, T11>>, Expression<Func<TSender, T12>>, Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, IObservedChange<TSender, T5>, IObservedChange<TSender, T6>, IObservedChange<TSender, T7>, IObservedChange<TSender, T8>, IObservedChange<TSender, T9>, IObservedChange<TSender, T10>, IObservedChange<TSender, T11>, IObservedChange<TSender, T12>, TRet>, bool)

Remarks

Initializes a new instance of the InMemoryBlobCacheBase class.

Constructors

InMemoryBlobCacheBase(ISerializer?)

Initializes a new instance of the InMemoryBlobCacheBase class with default scheduler.

protected InMemoryBlobCacheBase(ISerializer? serializer)

Parameters

serializer ISerializer

The serializer to use for object serialization/deserialization.

InMemoryBlobCacheBase(IScheduler, ISerializer?)

Base class for in-memory blob cache implementations that provides common functionality for all serialization-specific InMemoryBlobCache implementations.

protected InMemoryBlobCacheBase(IScheduler scheduler, ISerializer? serializer)

Parameters

scheduler IScheduler

The scheduler to use for Observable based operations.

serializer ISerializer

The serializer to use for object serialization/deserialization.

Remarks

Initializes a new instance of the InMemoryBlobCacheBase class.

Properties

ForcedDateTimeKind

Gets or sets the DateTimeKind handling for BSON readers to be forced.

public DateTimeKind? ForcedDateTimeKind { get; set; }

Property Value

DateTimeKind?

Remarks

By default, BsonReader uses a DateTimeKind of Local and see BsonWriter uses Utc. Thus, DateTimes are serialized as UTC but deserialized as local time. To force BSON readers to use some other DateTimeKind, you can set this value.

HttpService

Gets or sets the HTTP service.

public IHttpService HttpService { get; set; }

Property Value

IHttpService

The HTTP service.

Scheduler

Gets the IScheduler used to defer operations. By default, this is BlobCache.TaskpoolScheduler.

public IScheduler Scheduler { get; }

Property Value

IScheduler

Serializer

Gets the serializer.

public ISerializer Serializer { get; }

Property Value

ISerializer

The serializer.

Methods

Dispose()

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the InMemoryBlobCacheBase and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

Flush()

This method guarantees that all in-flight inserts have completed and any indexes have been written to disk.

public IObservable<Unit> Flush()

Returns

IObservable<Unit>

A signal indicating when the flush is complete.

Flush(Type)

This method guarantees that all in-flight inserts have completed and any indexes have been written to disk.

public IObservable<Unit> Flush(Type type)

Parameters

type Type

The type.

Returns

IObservable<Unit>

A signal indicating when the flush is complete.

Get(IEnumerable<string>)

Gets a observable of key value pairs with the specified keys with their corresponding values.

public IObservable<KeyValuePair<string, byte[]>> Get(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

The keys to get the values for.

Returns

IObservable<KeyValuePair<string, byte[]>>

A observable with the specified values.

Get(IEnumerable<string>, Type)

Gets a observable of key value pairs with the specified keys with their corresponding values.

public IObservable<KeyValuePair<string, byte[]>> Get(IEnumerable<string> keys, Type type)

Parameters

keys IEnumerable<string>

The keys to get the values for.

type Type

The type.

Returns

IObservable<KeyValuePair<string, byte[]>>

A observable with the specified values.

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.

public IObservable<byte[]?> Get(string key)

Parameters

key string

The key to return asynchronously.

Returns

IObservable<byte[]>

A Future result representing the byte data.

Get(string, Type)

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.

public IObservable<byte[]?> Get(string key, Type type)

Parameters

key string

The key to return asynchronously.

type Type

The type.

Returns

IObservable<byte[]>

A Future result representing the byte data.

GetAll(Type)

Gets a observable of key value pairs with the specified keys with their corresponding values.

public IObservable<KeyValuePair<string, byte[]>> GetAll(Type type)

Parameters

type Type

The type.

Returns

IObservable<KeyValuePair<string, byte[]>>

A observable with the specified values.

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.

public IObservable<string> GetAllKeys()

Returns

IObservable<string>

A list of valid keys for the cache.

GetAllKeys(Type)

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.

public IObservable<string> GetAllKeys(Type type)

Parameters

type Type

The type.

Returns

IObservable<string>

A list of valid keys for the cache.

GetAllObjects<T>()

Return all objects of a specific Type in the cache.

public IObservable<IEnumerable<T>> GetAllObjects<T>()

Returns

IObservable<IEnumerable<T>>

A Future result representing all objects in the cache with the specified Type.

Type Parameters

T

The type of object to retrieve.

GetCreatedAt(IEnumerable<string>)

Gets a observable of key value pairs with the specified keys with their corresponding created DateTimeOffset if it's available.

public IObservable<(string Key, DateTimeOffset? Time)> GetCreatedAt(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

The keys to get the values for.

Returns

IObservable<(string Key, DateTimeOffset? Time)>

A observable with the specified values.

GetCreatedAt(IEnumerable<string>, Type)

Gets a observable of key value pairs with the specified keys with their corresponding created DateTimeOffset if it's available.

public IObservable<(string Key, DateTimeOffset? Time)> GetCreatedAt(IEnumerable<string> keys, Type type)

Parameters

keys IEnumerable<string>

The keys to get the values for.

type Type

The type.

Returns

IObservable<(string Key, DateTimeOffset? Time)>

A observable with the specified values.

GetCreatedAt(string)

Returns the time that the key was added to the cache, or returns null if the key isn't in the cache.

public IObservable<DateTimeOffset?> GetCreatedAt(string key)

Parameters

key string

The key to return the date for.

Returns

IObservable<DateTimeOffset?>

The date the key was created on.

GetCreatedAt(string, Type)

Returns the time that the key was added to the cache, or returns null if the key isn't in the cache.

public IObservable<DateTimeOffset?> GetCreatedAt(string key, Type type)

Parameters

key string

The key to return the date for.

type Type

The type.

Returns

IObservable<DateTimeOffset?>

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.

public IObservable<DateTimeOffset?> GetObjectCreatedAt<T>(string key)

Parameters

key string

The key to return the date for.

Returns

IObservable<DateTimeOffset?>

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 using the configured serializer.

public IObservable<T?> GetObject<T>(string key)

Parameters

key string

The 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 to retrieve.

Insert(IEnumerable<KeyValuePair<string, byte[]>>, DateTimeOffset?)

Inserts the specified key/value pairs into the blob.

public IObservable<Unit> Insert(IEnumerable<KeyValuePair<string, byte[]>> keyValuePairs, DateTimeOffset? absoluteExpiration = null)

Parameters

keyValuePairs IEnumerable<KeyValuePair<string, byte[]>>

The key/value to insert.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<Unit>

A observable which signals when complete.

Insert(IEnumerable<KeyValuePair<string, byte[]>>, Type, DateTimeOffset?)

Inserts the specified key/value pairs into the blob.

public IObservable<Unit> Insert(IEnumerable<KeyValuePair<string, byte[]>> keyValuePairs, Type type, DateTimeOffset? absoluteExpiration = null)

Parameters

keyValuePairs IEnumerable<KeyValuePair<string, byte[]>>

The key/value to insert.

type Type

The type.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<Unit>

A observable which signals when complete.

Insert(string, byte[], DateTimeOffset?)

Insert a blob into the cache with the specified key and expiration date.

public IObservable<Unit> Insert(string key, byte[] data, DateTimeOffset? absoluteExpiration = null)

Parameters

key string

The key to use for the data.

data byte[]

The data to save in the cache.

absoluteExpiration DateTimeOffset?

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.

Insert(string, byte[], Type, DateTimeOffset?)

Insert a blob into the cache with the specified key and expiration date.

public IObservable<Unit> Insert(string key, byte[] data, Type type, DateTimeOffset? absoluteExpiration = null)

Parameters

key string

The key to use for the data.

data byte[]

The data to save in the cache.

type Type

The type.

absoluteExpiration DateTimeOffset?

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 using the configured serializer.

public IObservable<Unit> InsertObject<T>(string key, T value, DateTimeOffset? absoluteExpiration = null)

Parameters

key string

The key to associate with the object.

value T

The object to serialize.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<Unit>

A Future result representing the completion of the insert.

Type Parameters

T

The type of object to insert.

Invalidate(IEnumerable<string>)

Invalidates all the entries at the specified keys, causing them in future to have to be re-fetched.

public IObservable<Unit> Invalidate(IEnumerable<string> keys)

Parameters

keys IEnumerable<string>

The keys to invalid.

Returns

IObservable<Unit>

A observable which signals when complete.

Invalidate(IEnumerable<string>, Type)

Invalidates all the entries at the specified keys, causing them in future to have to be re-fetched.

public IObservable<Unit> Invalidate(IEnumerable<string> keys, Type type)

Parameters

keys IEnumerable<string>

The keys to invalid.

type Type

The type to invalidate.

Returns

IObservable<Unit>

A observable which signals when complete.

Invalidate(string)

Remove a key from the cache. If the key doesn't exist, this method should do nothing and return (not throw KeyNotFoundException).

public IObservable<Unit> Invalidate(string key)

Parameters

key string

The key to remove from the cache.

Returns

IObservable<Unit>

A signal indicating when the invalidate is complete.

Invalidate(string, Type)

Remove a key from the cache. If the key doesn't exist, this method should do nothing and return (not throw KeyNotFoundException).

public IObservable<Unit> Invalidate(string key, Type type)

Parameters

key string

The key to remove from the cache.

type Type

The type.

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.

public IObservable<Unit> InvalidateAll()

Returns

IObservable<Unit>

A signal indicating when the invalidate is complete.

InvalidateAll(Type)

Invalidates all entries for the specified type.

public IObservable<Unit> InvalidateAll(Type type)

Parameters

type Type

The type to invalidate.

Returns

IObservable<Unit>

A signal indicating when the invalidate is complete.

InvalidateAllObjects<T>()

Invalidates all objects of the specified type.

public IObservable<Unit> InvalidateAllObjects<T>()

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.

public IObservable<Unit> InvalidateObject<T>(string key)

Parameters

key string

The 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.

UpdateExpiration(IEnumerable<string>, DateTimeOffset?)

Updates the expiration date for multiple existing cache entries without reading or writing the cached data. This is useful when a server returns a NotModified response and you want to extend the cache expiration.

public IObservable<Unit> UpdateExpiration(IEnumerable<string> keys, DateTimeOffset? absoluteExpiration)

Parameters

keys IEnumerable<string>

The keys of the cache entries to update.

absoluteExpiration DateTimeOffset?

The new expiration date. Pass null for no expiration.

Returns

IObservable<Unit>

A signal indicating when the operation is complete.

UpdateExpiration(IEnumerable<string>, Type, DateTimeOffset?)

Updates the expiration date for multiple existing cache entries without reading or writing the cached data. This is useful when a server returns a NotModified response and you want to extend the cache expiration.

public IObservable<Unit> UpdateExpiration(IEnumerable<string> keys, Type type, DateTimeOffset? absoluteExpiration)

Parameters

keys IEnumerable<string>

The keys of the cache entries to update.

type Type

The type of the cached objects.

absoluteExpiration DateTimeOffset?

The new expiration date. Pass null for no expiration.

Returns

IObservable<Unit>

A signal indicating when the operation is complete.

UpdateExpiration(string, DateTimeOffset?)

Updates the expiration date for an existing cache entry without reading or writing the cached data. This is useful when a server returns a NotModified response and you want to extend the cache expiration.

public IObservable<Unit> UpdateExpiration(string key, DateTimeOffset? absoluteExpiration)

Parameters

key string

The key of the cache entry to update.

absoluteExpiration DateTimeOffset?

The new expiration date. Pass null for no expiration.

Returns

IObservable<Unit>

A signal indicating when the operation is complete.

UpdateExpiration(string, Type, DateTimeOffset?)

Updates the expiration date for an existing cache entry without reading or writing the cached data. This is useful when a server returns a NotModified response and you want to extend the cache expiration.

public IObservable<Unit> UpdateExpiration(string key, Type type, DateTimeOffset? absoluteExpiration)

Parameters

key string

The key of the cache entry to update.

type Type

The type of the cached object.

absoluteExpiration DateTimeOffset?

The new expiration date. Pass null for no expiration.

Returns

IObservable<Unit>

A signal indicating when the operation is complete.

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).

public IObservable<Unit> Vacuum()

Returns

IObservable<Unit>

A signal indicating when the operation is complete.