Primary Data Caching Provider
IDataCachingService
in assembly SanteDB.Core.Api version 3.0.1980.0
Summary
Defines a service which can be used by callers to store full IdentifiedData RIM objects in a transient cache.
Description
The data caching service is primarily used to store fully loaded objects from the database. This loading into the cache reduces the load on the persistence layer of the SanteDB host context. The data persistence layers themselves will use implementations of this class to prevent re-loading of data to/from the disk system. The process on a read is generally:
Check the cache service to determine if the data has already been loaded
If not found in cache load the data from disk / database
Add the object to the cache
Of course, keeping the cache service in a consistent state is tantamount to the reliable functioning of SanteDB, this means that any update, delete or create on an object that already exists in cache results in its eviction from the cache via the Guid)) method.
Events
Event | Type | Description |
---|---|---|
Added | EventHandler<DataCacheEventArgs> | Fired after an object has successfully been committed to the cache |
Updated | EventHandler<DataCacheEventArgs> | Fired after an object has successfully been updated within the cache |
Removed | EventHandler<DataCacheEventArgs> | Fired after an object has successfully been evicted from cache |
Properties
Property | Type | Access | Description |
---|---|---|---|
Size | Int64 | R | Gets the current size of the cache in objects |
Operations
Operation | Response/Return | Input/Parameter | Description |
---|---|---|---|
GetCacheItem | TData | Guid key | Gets the cache item specified by returning it as a casted instance of . Returning the default of if the object doesn't exist or if the object is the wrong type. |
GetCacheItem | IdentifiedData | Guid key | Gets the cache item specified by regardless of the type of data |
Add | void | IdentifiedData data | Adds to the cache |
Remove | void | Guid key | Removes/evicts an object with identifier from the cache |
Remove | void | IdentifiedData data | Removes/evicts an object with identifier from the cache |
Clear | void | none | TODO |
Exists | Boolean | Guid id | Returns true if the specified cache item exists |
Implementations
Memory Cache Service - (SanteDB.Caching.Memory)
Implementation of the IDataCachingService which uses the in-process memory to cache objects
Description
The memory cache service uses the MemoryCache class as a backing cache for the SanteDB host instance. This caching provider provides benefits over a common, shared cache like REDIS in that:
It does not require the setup of a third-party service to operate
The cache objects are directly accessed and not serialized
The cache objects are protected within the host process memory
The access is very fast - there is no interconnection with another process
This cache service should only be used in cases when there is a single SanteDB server and there is no need for sharing cache objects between application services.
This class uses the TTL setting from the MemoryCacheConfigurationSection to determine the length of time that cache entries are valid
Service Registration
REDIS Data Caching Service - (SanteDB.Caching.Redis)
An implementation of the IDataCachingService which uses REDIS
Description
This implementation of the caching service uses the XMLSerializer in .NET to serialize any object passed in via the IdentifiedData)) method. The data is then compressed (if configured) and sent to the configured REDIS server.
The use of the .NET XML serializer over the Newtonsoft JSON serializer for caching was chosen since the serializer operates on streams (saves string conversions) and pre-compiles the serialization classes on .NET Framework implementations (Mono implementations use relfection)
The caching data is stored in database 1 of the REDIS server.
Service Registration
Example Implementation
References
Last updated