Show / Hide Table of Contents

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

Inheritance
object
Cache<TKey, TValue>
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 Source

CacheSize

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 Source

CacheObject(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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

RefreshCache()

Refreshes the cache by removing deleted objects

Declaration
public void RefreshCache()
| Edit this page View Source

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

Extension Methods

ReflectionUtilities.ReflectCallMethod(object, string, object[], BindingFlags)
ReflectionUtilities.ReflectGetField(object, string, BindingFlags)
ReflectionUtilities.ReflectGetMethod(object, string, BindingFlags)
ReflectionUtilities.ReflectGetProperty(object, string, BindingFlags)
ReflectionUtilities.ReflectSetField(object, string, object, BindingFlags)
ReflectionUtilities.ReflectSetProperty(object, string, object, BindingFlags)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Generated by DocFX
☀
☾