Click or drag to resize

MemoryCacheService Class

Implementation of the IDataCachingService which uses the in-process memory to cache objects
Inheritance Hierarchy

Namespace:  SanteDB.Caching.Memory
Assembly:  SanteDB.Caching.Memory (in SanteDB.Caching.Memory.dll) Version: 2.2.1
Syntax
public class MemoryCacheService : IDataCachingService, 
	IServiceImplementation, IDaemonService

The MemoryCacheService type exposes the following members.

Constructors
  NameDescription
Public methodMemoryCacheService
Creates a new memory cache service
Top
Properties
  NameDescription
Public propertyIsRunning
True when the memory cache is running
Public propertyServiceName
Gets the service name
Public propertySize
Gets the current size of the cache in objects
Top
Methods
  NameDescription
Public methodAdd
Adds data to the cache
Public methodClear
Purges the entire cache of all entries
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetCacheItem(Guid)
Gets the cache item specified by key regardless of the type of data
Public methodGetCacheItemTData(Guid)
Gets the cache item specified by key returning it as a casted instance of TData. Returning the default of TData if the object doesn't exist or if the object is the wrong type.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRemove(Guid)
Removes/evicts an object with identifier key from the cache
Public methodRemove(IdentifiedData)
Removes/evicts the provided object form cache if available
Public methodStart
Indicates the caller wishes to start the daemon service lifecycle
Public methodStop
Indicates the caller wishes to stop the daemon service
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Events
  NameDescription
Public eventAdded
Fired after an object has successfully been committed to the cache
Public eventRemoved
Fired after an object has successfully been evicted from cache
Public eventStarted
Fired when the daemon service has completed it start procedure.
Public eventStarting
Fired when the daemon service has commenced start but has not yet finished
Public eventStopped
Fired when the daemon has completed its stop procedure
Public eventStopping
Fired when the daemon service has commenced stop but has not yet been fully shut down.
Public eventUpdated
Fired after an object has successfully been updated within the cache
Top
Extension Methods
  NameDescription
Public Extension MethodConvertTReturn
The purpose of this method is to convert object me to TReturn. Why? Because if you have an instance of Act that actually needs to be a SubstanceAdministration we can't just cast so we have to copy.
(Defined by ExtensionMethods.)
Public Extension MethodGetInstanceOfTDomain
Gets an instance of TDomain from me
(Defined by ModelExtensions.)
Top
Remarks

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

See Also