Ad-Hoc Cache Provider

IAdhocCacheService in assembly SanteDB.Core.Api version 2.1.151.0

Summary

Defines a service which can store commonly used objects in a transient cache

Description

The ad-hoc cache service differs from the data cache in that the ad-hoc cache can be used to store any data with any key and value within the caching technology implementation. The cache is commonly used to store repeat or commonly fetched data (for example policy decision outcomes, keys, reference term lookups, etc.).

The cache can be used to save fetching and querying data to/from the persistence layer.

Note to Implementers: Your implementation of this interface should not be a persistent cache (if possible to enforce). The callers of this interface typically assume a short lifecycle of data within the cache, and transient, rapid access should be prioritized over durability.

Operations

OperationResponse/ReturnInput/ParameterDescription

Add

void

String key T value Nullable<TimeSpan> timeout

Add the specified object to the cache

Get

T

String key

Gets the specified object from the cache

Remove

Boolean

String key

Removes the specified object from the adhoc

Implementations

Memory Ad-Hoc Cache Service - (SanteDB.Caching.Memory)

An implementation of IAdhocCacheService which uses the in-process memory cache

Description

This implementation of the adhoc caching service uses in-process memory to store unstructured data which is commonly used in the application.

Service Registration

...
<section xsi:type="ApplicationServiceContextConfigurationSection" threadPoolSize="4">
	<serviceProviders>
		...
		<add type="SanteDB.Caching.Memory.MemoryAdhocCacheService, SanteDB.Caching.Memory, Version=2.1.151.0, Culture=neutral, PublicKeyToken=null" />
		...
	</serviceProviders>

RedisAdhocCache - (SanteDB.Caching.Redis)

An implementation of the IAdhocCacheService which uses REDIS as the cache provider

Description

This implementation of the REDIS ad-hoc cache provider serializes any data passed via TimeSpan})) to a JSON representation, then compresses (optional) the data and stores it in REDIS as a simple string

The data is stored in database 3 of the REDIS server

Service Registration

...
<section xsi:type="ApplicationServiceContextConfigurationSection" threadPoolSize="4">
	<serviceProviders>
		...
		<add type="SanteDB.Caching.Redis.RedisAdhocCache, SanteDB.Caching.Redis, Version=2.1.151.0, Culture=neutral, PublicKeyToken=null" />
		...
	</serviceProviders>

Example Implementation

/// Example Implementation
using SanteDB.Core.Services;
/// Other usings here
public class MyAdhocCacheService : SanteDB.Core.Services.IAdhocCacheService { 
	public String ServiceName => "My own IAdhocCacheService service";
	/// <summary>
	/// Add the specified object to the cache
	/// </summary>
	public void Add<T>(String key,T value,Nullable<TimeSpan> timeout){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Gets the specified object from the cache
	/// </summary>
	public T Get<T>(String key){
		throw new System.NotImplementedException();
	}
	/// <summary>
	/// Removes the specified object from the adhoc
	/// </summary>
	public Boolean Remove(String key){
		throw new System.NotImplementedException();
	}
}

References

Last updated