Show / Hide Table of Contents

Class CacheStore

Represents an efficient in-memory cache of expiring optionally-prioritized objects. This class is higly optimized for caching of business objects in data store implementations and does not guarantee that all hash collisions are handled, that is - some data may be overridden. The implementation relies on 2 stage hashing, where the second collision replaces the existing item with the colliding one if items are equal in their priorities. The degree of collisions is controlled by 'bucketSize' and 'recPerPage' parameters that are passed to the store per table, so basically the tables are capped at a certain size and can not change (bucketSize*recPerPage). The lookup implementation is 100% lock-free, whereas the degree of mutability-related locking is controlled by 'lockCount' per table. This class is thread safe for reading and writing cache items, however it does not guarantee instant read/write consistency between threads.

Inheritance
System.Object
DisposableObject
ApplicationComponent
CacheStore
Implements
IApplicationComponent
System.IDisposable
INamed
IConfigurable
IInstrumentable
IExternallyParameterized
Inherited Members
ApplicationComponent.AllComponents
ApplicationComponent.GetAppComponentBySID(UInt64)
ApplicationComponent.GetAppComponentByCommonName(String)
ApplicationComponent.ComponentSID
ApplicationComponent.ComponentStartTime
ApplicationComponent.ComponentCommonName
ApplicationComponent.ComponentDirector
DisposableObject.DisposeAndNull<T>(T)
DisposableObject.DisposeStarted
DisposableObject.Disposed
DisposableObject.EnsureObjectNotDisposed()
DisposableObject.Dispose()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX.DataAccess.Cache
Assembly: NFX.dll
Syntax
public sealed class CacheStore : ApplicationComponent, IApplicationComponent, IDisposable, INamed, IConfigurable, IInstrumentable, IExternallyParameterized
Remarks

Perfomance testing of this class vs. System.Runtime.Caching.MemoryCache storing a typical database record identified by a long key: NFX is 2.5-5 times faster for concurrent reads and takes 20% less ram. NFX is 1.3-2.5 times faster for writes

Constructors

CacheStore()

Declaration
public CacheStore()

CacheStore(String)

Declaration
public CacheStore(string name)
Parameters
Type Name Description
System.String name

Fields

CONFIG_CACHE_SECTION

Declaration
public const string CONFIG_CACHE_SECTION = "cache"
Field Value
Type Description
System.String

CONFIG_STORE_SECTION

Declaration
public const string CONFIG_STORE_SECTION = "store"
Field Value
Type Description
System.String

CONFIG_TABLE_SECTION

Declaration
public const string CONFIG_TABLE_SECTION = "table"
Field Value
Type Description
System.String

Properties

Count

Returns total number of records in all tables in the store

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32

DefaultTableOptions

Sets default options for a table which is not found in TableOptions collection. If this property is null then every table assumes the set of constant values defined in Table class

Declaration
public TableOptions DefaultTableOptions { get; set; }
Property Value
Type Description
TableOptions

ExternalParameters

Returns named parameters that can be used to control this component

Declaration
public IEnumerable<KeyValuePair<string, Type>> ExternalParameters { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.Type>>

InstrumentationEnabled

When true, emits instrumentation messages

Declaration
[Config]
[ExternalParameter(new string[]{"cache", "instrumentation"})]
public bool InstrumentationEnabled { get; set; }
Property Value
Type Description
System.Boolean

Item[String]

Returns a table by its name creating its' instance if such table is not in the set. Table names are case-insensitive

Declaration
public Table this[string table] { get; }
Parameters
Type Name Description
System.String table
Property Value
Type Description
Table

Item[String, UInt64]

Returns a cached record from named table identified by the key or null if this item was not found

Declaration
public CacheRec this[string table, ulong key] { get; }
Parameters
Type Name Description
System.String table
System.UInt64 key
Property Value
Type Description
CacheRec

Name

Returns store name which can be used to identify stores in registries and instrumentation/telemetry outputs

Declaration
public string Name { get; }
Property Value
Type Description
System.String

ParallelSweep

When enabled, uses parallel execution while sweeping tables, otherwise sweeps sequentially (default behavior)

Declaration
[Config]
[ExternalParameter(new string[]{"cache"})]
public bool ParallelSweep { get; set; }
Property Value
Type Description
System.Boolean

TableOptions

Returns table options - used for table creation

Declaration
public Registry<TableOptions> TableOptions { get; }
Property Value
Type Description
Registry<TableOptions>

Tables

Returns all tables that this store currently contains

Declaration
public IRegistry<Table> Tables { get; }
Property Value
Type Description
IRegistry<Table>

Methods

Configure(IConfigSectionNode)

Configures store from node, if node==null then store will be configured by named node of 'app/cache/store[name=X]' path, if such path is not found the store tries to find 'app/cache/store[!name]' (node without name)

Declaration
public void Configure(IConfigSectionNode node)
Parameters
Type Name Description
IConfigSectionNode node

Destructor()

Declaration
protected override void Destructor()
Overrides
ApplicationComponent.Destructor()

DropTable(String)

Drops table by name returning true if it was found and removed

Declaration
public bool DropTable(string name)
Parameters
Type Name Description
System.String name
Returns
Type Description
System.Boolean

ExternalGetParameter(String, out Object, String[])

Gets external parameter value returning true if parameter was found

Declaration
public bool ExternalGetParameter(string name, out object value, params string[] groups)
Parameters
Type Name Description
System.String name
System.Object value
System.String[] groups
Returns
Type Description
System.Boolean

ExternalParametersForGroups(String[])

Returns named parameters that can be used to control this component

Declaration
public IEnumerable<KeyValuePair<string, Type>> ExternalParametersForGroups(params string[] groups)
Parameters
Type Name Description
System.String[] groups
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.Type>>

ExternalSetParameter(String, Object, String[])

Sets external parameter value returning true if parameter was found and set

Declaration
public bool ExternalSetParameter(string name, object value, params string[] groups)
Parameters
Type Name Description
System.String name
System.Object value
System.String[] groups
Returns
Type Description
System.Boolean

Implements

IApplicationComponent
System.IDisposable
INamed
IConfigurable
IInstrumentable
IExternallyParameterized

Extension Methods

MiscUtils.NonNull<T>(T, Func<Exception>, String)
ObjectValueConversion.AsString(Object, String, ConvertErrorHandling)
ObjectValueConversion.AsNonNullOrEmptyString(Object)
ObjectValueConversion.AsLaconicConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsJSONConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsXMLConfig(Object, ConfigSectionNode, ConvertErrorHandling)
ObjectValueConversion.AsChar(Object, Char, ConvertErrorHandling)
ObjectValueConversion.AsNullableChar(Object, Nullable<Char>, ConvertErrorHandling)
ObjectValueConversion.AsByte(Object, Byte, ConvertErrorHandling)
ObjectValueConversion.AsNullableByte(Object, Nullable<Byte>, ConvertErrorHandling)
ObjectValueConversion.AsSByte(Object, SByte, ConvertErrorHandling)
ObjectValueConversion.AsNullableSByte(Object, Nullable<SByte>, ConvertErrorHandling)
ObjectValueConversion.AsShort(Object, Int16, ConvertErrorHandling)
ObjectValueConversion.AsNullableShort(Object, Nullable<Int16>, ConvertErrorHandling)
ObjectValueConversion.AsUShort(Object, UInt16, ConvertErrorHandling)
ObjectValueConversion.AsNullableUShort(Object, Nullable<UInt16>, ConvertErrorHandling)
ObjectValueConversion.AsInt(Object, Int32, ConvertErrorHandling)
ObjectValueConversion.AsNullableInt(Object, Nullable<Int32>, ConvertErrorHandling)
ObjectValueConversion.AsUInt(Object, UInt32, ConvertErrorHandling)
ObjectValueConversion.AsNullableUInt(Object, Nullable<UInt32>, ConvertErrorHandling)
ObjectValueConversion.AsLong(Object, Int64, ConvertErrorHandling)
ObjectValueConversion.AsNullableLong(Object, Nullable<Int64>, ConvertErrorHandling)
ObjectValueConversion.AsULong(Object, UInt64, ConvertErrorHandling)
ObjectValueConversion.AsNullableULong(Object, Nullable<UInt64>, ConvertErrorHandling)
ObjectValueConversion.AsDouble(Object, Double, ConvertErrorHandling)
ObjectValueConversion.AsNullableDouble(Object, Nullable<Double>, ConvertErrorHandling)
ObjectValueConversion.AsFloat(Object, Single, ConvertErrorHandling)
ObjectValueConversion.AsNullableFloat(Object, Nullable<Single>, ConvertErrorHandling)
ObjectValueConversion.AsDecimal(Object, Decimal, ConvertErrorHandling)
ObjectValueConversion.AsNullableDecimal(Object, Nullable<Decimal>, ConvertErrorHandling)
ObjectValueConversion.AsBool(Object, Boolean, ConvertErrorHandling)
ObjectValueConversion.AsNullableBool(Object, Nullable<Boolean>, ConvertErrorHandling)
ObjectValueConversion.AsGUID(Object, Guid, ConvertErrorHandling)
ObjectValueConversion.AsNullableGUID(Object, Nullable<Guid>, ConvertErrorHandling)
ObjectValueConversion.AsDateTime(Object)
ObjectValueConversion.AsDateTime(Object, DateTime, ConvertErrorHandling)
ObjectValueConversion.AsNullableDateTime(Object, Nullable<DateTime>, ConvertErrorHandling)
ObjectValueConversion.AsGDID(Object)
ObjectValueConversion.AsGDID(Object, GDID, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDID(Object, Nullable<GDID>, ConvertErrorHandling)
ObjectValueConversion.AsGDIDSymbol(Object)
ObjectValueConversion.AsGDIDSymbol(Object, GDIDSymbol, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDIDSymbol(Object, Nullable<GDIDSymbol>, ConvertErrorHandling)
ObjectValueConversion.AsTimeSpan(Object)
ObjectValueConversion.AsTimeSpan(Object, TimeSpan, ConvertErrorHandling)
ObjectValueConversion.AsNullableTimeSpan(Object, Nullable<TimeSpan>, ConvertErrorHandling)
ObjectValueConversion.AsEnum<TEnum>(Object, TEnum, ConvertErrorHandling)
ObjectValueConversion.AsNullableEnum<TEnum>(Object, Nullable<TEnum>, ConvertErrorHandling)
ObjectValueConversion.AsUri(Object, Uri, ConvertErrorHandling)
JSONExtensions.ToJSON(Object, JSONWritingOptions)
JSONExtensions.ToJSON(Object, TextWriter, JSONWritingOptions)
JSONExtensions.ToJSON(Object, Stream, JSONWritingOptions, Encoding)
ErlObject.ToErlObject(Object)
ErlObject.ToErlObject(Object, ErlTypeOrder, Boolean)
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX