Photon Server API
Public Member Functions | Protected Member Functions | Properties | List of all members
ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue > Class Template Referenceabstract

A SynchronizedSingletonFactory<TKey,TValue> that uses the ASP.NET cache. It offers limited lifetime for items and requires no locking to access items that are cached. The subclasses support sliding and absolute timeouts. More...

Inheritance diagram for ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >:
ExitGames.Threading.CachedSingletonFactory.CachedSingletonFactoryAbsolute< TKey, TValue > ExitGames.Threading.CachedSingletonFactory.CachedSingletonFactorySliding< TKey, TValue >

Public Member Functions

virtual TValue Get (TKey key, CreateMethodDelegate< TKey, TValue > createMethod)
 Gets an existing value for a key or creates a new one. More...
 
TValue Get (TKey key)
 Gets an existing value for a key or creates a new one with the default DoCreateMethod. More...
 
TValue GetBlockingInstance (TKey key)
 Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is guarded with a sync root that is unique per key. This algorithm is ideal for creation methods that do not return fast. More...
 
TValue GetBlockingInstance (TKey key, CreateMethodDelegate< TKey, TValue > createMethod)
 Gets an existing value for a key or creates a new one. The creation of a new instance is guarded with a sync root that is unique per key. This algorithm is ideal for creation methods that do not return fast. More...
 
TValue GetBlockingOverall (TKey key)
 Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is guarded with a global SynchronizedSingletonFactory<TKey,TValue>.WriterLock. This algorithm is ideal for creation methods that return very fast. More...
 
TValue GetBlockingOverall (TKey key, CreateMethodDelegate< TKey, TValue > createMethod)
 Gets an existing value for a key or creates a new one. The creation of a new instance is guarded with a global SynchronizedSingletonFactory<TKey,TValue>.WriterLock. This algorithm is ideal for creation methods that return very fast. More...
 
TValue GetNonBlocking (TKey key)
 Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is not guarded. This introduces a risk that the creation method is called multiple times for the same key at the same time. Only one of the created values is added. This algorithm is ideal for creation methods that are either not likely to be called multiple times at the same time or that have an unpredictable execution time and a low usage of local reosurces. More...
 
TValue GetNonBlocking (TKey key, CreateMethodDelegate< TKey, TValue > createMethod)
 Gets an existing value for a key or creates a new one. The creation of a new instance is not guarded. This introduces a risk that the creation method is called multiple times for the same key at the same time. Only one of the created values is added. This algorithm is ideal for creation methods that are either not likely to be called multiple times at the same time or that have an unpredictable execution time and a low usage of local reosurces. More...
 
override bool Remove (CacheKey< TKey, TValue > key)
 Removes a value from the cache and from the SynchronizedSingletonFactory<TKey,TValue>.Instances. More...
 
bool Remove (TKey key)
 Removes a value from the cache and from the SynchronizedSingletonFactory<TKey,TValue>.Instances. More...
 
override bool TryGet (CacheKey< TKey, TValue > key, out CacheValue< TKey, TValue > value)
 Tries to get an existing value for the key. More...
 
virtual bool TryGet (TKey key, out TValue value)
 Tries to get an existing value for the key. More...
 

Protected Member Functions

 SynchronizedCachedSingletonFactory (CreateMethodDelegate< TKey, TValue > defaultCreateMethod, Action< TKey, TValue > removeCallback, TimeSpan cacheTimeSpan, int lockTimeout)
 Initializes a new instance of the SynchronizedCachedSingletonFactory<TKey,TValue> class. More...
 
override void DoAdd (CacheKey< TKey, TValue > key, CacheValue< TKey, TValue > value)
 Adds a value to the SynchronizedSingletonFactory<TKey,TValue>.Instances and the cache. Calling methods need to guard the SynchronizedSingletonFactory<TKey,TValue>.Instances with a SynchronizedSingletonFactory<TKey,TValue>.WriterLock. Calling methods are: SynchronizedSingletonFactory<TKey,TValue>.Add, GetBlockingInstance, GetNonBlocking and GetBlockingOverall. More...
 
abstract void InsertIntoCache (string key, CacheValue< TKey, TValue > instance, TimeSpan cacheTimeSpan, CacheItemRemovedCallback callback)
 Inserts an item into the asp net cache. The subclass determines whether to use sliding or absolute caching. More...
 

Properties

virtual TimeSpan CacheTimeOut [get, set]
 Gets or sets the caching timeout. More...
 
CreateMethodDelegate< TKey, TValue > DoCreateMethod [get, set]
 Gets or sets the default creation method. More...
 
Action< TKey, TValue > RemoveCallback [get, set]
 Gets or sets the callback for removed items. More...
 
Cache Cache [get]
 Gets the asp net cache. More...
 

Detailed Description

A SynchronizedSingletonFactory<TKey,TValue> that uses the ASP.NET cache. It offers limited lifetime for items and requires no locking to access items that are cached. The subclasses support sliding and absolute timeouts.

Template Parameters
TKeyThe type of the key.
TValueThe type of the value.

Constructor & Destructor Documentation

ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.SynchronizedCachedSingletonFactory ( CreateMethodDelegate< TKey, TValue >  defaultCreateMethod,
Action< TKey, TValue >  removeCallback,
TimeSpan  cacheTimeSpan,
int  lockTimeout 
)
inlineprotected

Initializes a new instance of the SynchronizedCachedSingletonFactory<TKey,TValue> class.

Parameters
defaultCreateMethodThe default creattion method.
removeCallbackThe callback that is called when an item is removed.
cacheTimeSpanThe caching time.
lockTimeoutThe max wait time to avoid dead locks.

Member Function Documentation

override void ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.DoAdd ( CacheKey< TKey, TValue >  key,
CacheValue< TKey, TValue >  value 
)
inlineprotected
virtual TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.Get ( TKey  key,
CreateMethodDelegate< TKey, TValue >  createMethod 
)
inlinevirtual

Gets an existing value for a key or creates a new one.

Parameters
keyThe key.
createMethodThe creation method.
Returns
The value.

The default implementation uses the GetBlockingInstance algorithm. Override to change the behavior to GetNonBlocking or GetBlockingOverall

Gets an existing value for a key or creates a new one with the default DoCreateMethod.

Parameters
keyThe key.
Returns
The value for the key.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetBlockingInstance ( TKey  key)
inline

Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is guarded with a sync root that is unique per key. This algorithm is ideal for creation methods that do not return fast.

Parameters
keyThe key.
Returns
The value.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetBlockingInstance ( TKey  key,
CreateMethodDelegate< TKey, TValue >  createMethod 
)
inline

Gets an existing value for a key or creates a new one. The creation of a new instance is guarded with a sync root that is unique per key. This algorithm is ideal for creation methods that do not return fast.

Parameters
keyThe key.
createMethodThe creation method.
Returns
The value.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetBlockingOverall ( TKey  key)
inline

Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is guarded with a global SynchronizedSingletonFactory<TKey,TValue>.WriterLock. This algorithm is ideal for creation methods that return very fast.

Parameters
keyThe key.
Returns
The value.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetBlockingOverall ( TKey  key,
CreateMethodDelegate< TKey, TValue >  createMethod 
)
inline

Gets an existing value for a key or creates a new one. The creation of a new instance is guarded with a global SynchronizedSingletonFactory<TKey,TValue>.WriterLock. This algorithm is ideal for creation methods that return very fast.

Parameters
keyThe key.
createMethodThe creation method.
Returns
The value.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetNonBlocking ( TKey  key)
inline

Gets an existing value for a key or creates a new one with the default DoCreateMethod. The creation of a new instance is not guarded. This introduces a risk that the creation method is called multiple times for the same key at the same time. Only one of the created values is added. This algorithm is ideal for creation methods that are either not likely to be called multiple times at the same time or that have an unpredictable execution time and a low usage of local reosurces.

Parameters
keyThe key.
Returns
The value.
TValue ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.GetNonBlocking ( TKey  key,
CreateMethodDelegate< TKey, TValue >  createMethod 
)
inline

Gets an existing value for a key or creates a new one. The creation of a new instance is not guarded. This introduces a risk that the creation method is called multiple times for the same key at the same time. Only one of the created values is added. This algorithm is ideal for creation methods that are either not likely to be called multiple times at the same time or that have an unpredictable execution time and a low usage of local reosurces.

Parameters
keyThe key.
createMethodThe creation method.
Returns
The value.
abstract void ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.InsertIntoCache ( string  key,
CacheValue< TKey, TValue >  instance,
TimeSpan  cacheTimeSpan,
CacheItemRemovedCallback  callback 
)
protectedpure virtual

Inserts an item into the asp net cache. The subclass determines whether to use sliding or absolute caching.

Parameters
keyThe key.
instanceThe instance.
cacheTimeSpanThe cache time span.
callbackThe remove callback.

Implemented in ExitGames.Threading.CachedSingletonFactory.CachedSingletonFactoryAbsolute< TKey, TValue >, and ExitGames.Threading.CachedSingletonFactory.CachedSingletonFactorySliding< TKey, TValue >.

override bool ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.Remove ( CacheKey< TKey, TValue >  key)
inline

Removes a value from the cache and from the SynchronizedSingletonFactory<TKey,TValue>.Instances.

Parameters
keyThe key.
Returns
True if key was found and removed, otherwise false.

Removes a value from the cache and from the SynchronizedSingletonFactory<TKey,TValue>.Instances.

Parameters
keyThe key.
Returns
True if key was found and removed, otherwise false.
override bool ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.TryGet ( CacheKey< TKey, TValue >  key,
out CacheValue< TKey, TValue >  value 
)
inline

Tries to get an existing value for the key.

Parameters
keyThe key.
valueThe value.
Returns
True if a value was found, otherwise false.
virtual bool ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.TryGet ( TKey  key,
out TValue  value 
)
inlinevirtual

Tries to get an existing value for the key.

Parameters
keyThe key.
valueThe value.
Returns
True if a value was found, otherwise false.

Property Documentation

Gets the asp net cache.

virtual TimeSpan ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.CacheTimeOut
getset

Gets or sets the caching timeout.

CreateMethodDelegate<TKey, TValue> ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.DoCreateMethod
getset

Gets or sets the default creation method.

Action<TKey, TValue> ExitGames.Threading.CachedSingletonFactory.SynchronizedCachedSingletonFactory< TKey, TValue >.RemoveCallback
getset

Gets or sets the callback for removed items.