Class Cache<TKey, TValue>
A cache that stores objects in a dictonary structure. When an object gets destroyed or garbage collected, the cache object automatically removes it
Namespace: WeaverCore
Assembly: WeaverCore.dll
Syntax
public sealed class Cache<TKey, TValue> where TValue : class
Type Parameters
Name | Description |
---|---|
TKey | The key data type |
TValue | The value data type |
Properties
| Edit this page View SourceCacheSize
The amount of objects in the cache. This will include objects that are no longer alive. You can get an accurate count by calling RefreshCache() first
Declaration
public int CacheSize { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceCacheObject(TKey, TValue)
Caches an object
Declaration
public void CacheObject(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to cache the object under |
TValue | value | The object to cache |
GetCachedObject(TKey)
Gets the cached object based on the key. Make sure to use IsCached(TKey) before calling, or it could thrown an exception
Declaration
public TValue GetCachedObject(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to check the object under |
Returns
Type | Description |
---|---|
TValue | Returns a reference to the cached object |
GetCachedObject(TKey, out TValue)
Gets the cached object based on the key
Declaration
public bool GetCachedObject(TKey key, out TValue obj)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to check the object under |
TValue | obj | The reference to the cached object |
Returns
Type | Description |
---|---|
bool | Returns whether the object was in the cache or not |
IsCached(TKey)
Checks if an object under the specified key is still alive
Declaration
public bool IsCached(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to check the object under |
Returns
Type | Description |
---|---|
bool | Returns whether the object is still in the cache |
RefreshCache()
Refreshes the cache by removing deleted objects
Declaration
public void RefreshCache()
RemoveCachedObject(TKey)
Removes an object from the cache
Declaration
public void RemoveCachedObject(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the object to remove |