ICacheBase

Description

interface Tinman.Core.Caching.ICacheBase<TId>

Extended by

ICache
SimpleCache sealed

Base interface for cache-like data structures.

The following terms are used by this interface:

  • page:
    A page is a logical piece of information which is expensive to obtain or access.

  • cache:
    A cache is a container that can store a number of pages and provides fast access to them.

  • capacity:
    The capacity of a cache is the maximum number of pages that it can store.

  • page id:
    The page ID can be used to uniquely refer to a page.

  • page index:
    The page index is the storage position of the page in the cache container.

A ICacheBase object is responsible for the following tasks:

  • Page loading / unloading:
    When a page is requested for the first time, it must be loaded into the cache. If all caches pages are used, the oldest page must be evicted in order to make room for the new page. The load / unload actions are not performed by the cache itself. Pages are requested via Fetch. Page can be evicted by using one of the EvictAll, EvictId and EvictIndex methods.

  • Mapping of page IDs to page indices:
    For each cached paged, a mapping of the form {ID => index} is stored and maintained. The current mappings can be queried by using the GetId and GetIndex method.

Client code can use the cache page index values for storing additional data per cache page.

Public / Methods

Evict​All


public method EvictAll → ()

Evicts all pages from the cache.

Evict​Id


public method EvictId → (1)

pageId in : TId

The cache page ID.

Evicts the given page from the cache.

Requesting the given page later will cause a cache miss.

Evict​Index


public method EvictIndex → (1)

pageIndex in : int32

[0..ICacheBase.Capacity-1]
The cache page index.

Evicts the given page from the cache.

Requesting the given page later will cause a cache miss.

Fetch


public method Fetch → (1)

pageId in : TId

The page ID.

returns → int32
  • >= 0:
    The page is present in the cache, the return value is its index.

  • <=-1:
    The page is not present in the cache and shall be loaded into the cache using the page index given by -1-value, where value is the value that is returned by this method.

Fetches a page from the cache, loading it if necessary.

Get​Id


public method GetId → (1)

pageIndex in : int32

[0..ICacheBase.Capacity-1]
The page index.

returns → TId

The page ID.

Returns the page ID of the given page.

The state of the cache is not modified by this method.

Get​Index


public method GetIndex → (2)

pageId in : TId

The page ID.

hitPage opt : bool = false

Update state of the cache by hitting the page if it exists?

returns → int32

The cache page index or -1.

Returns the cache page index of the given page.

The state of the cache is not modified by this method if hitPage opt is false.

Use


public method Use → (1)

pageIndex in : int32

[0..ICacheBase.Capacity-1]
The page index.

The given cache page has been used.

Use this method to avoid specific pages to get evicted from the cache too soon.

Public / Attributes

Capacity


public attribute Capacity → (get)

value : int32

[>0]
The maximum number of entries this cache can hold.

The capacity of this cache.

Invalid​Id


public attribute InvalidId → (get)

value : TId

The invalid page ID value.

The page ID value that represents non-existent mappings.

Oldest


public attribute Oldest → (get)

value : int32

[-1..ICacheBase.Capacity-1]
Index of the least-recently used cache page or -1 if all pages are unused.

Returns the index of the oldest cache page.