Struct sierra::ResourceCache

source ·
pub struct ResourceCache<T> { /* private fields */ }
Expand description

General purpose cache for sierra resources. This cache evicts resources based on their last used epoch. Each time a resource is used, its last used epoch is updated to the current. The cache evicts all resources that have not been used for a certain amount of epochs.

This strategy works best for resources that may become obsolete and require substantial amount of memory while only few resources are in use so cache size is always low.

Implementations§

Creates a new empty cache.

Creates a new cache with preallocated resource capacity.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. Returns None if resource is not in cache. Returns Some if resource is in cache.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. Returns None if resource is not in cache. Returns Some if resource is in cache.

Fetches resource from cache. Resource last used epoch is not updated. This is useful when only shared reference to cache is available. Returns None if resource is not in cache. Returns Some if resource is in cache.

Fetches resource from cache. Resource last used epoch is not updated. This is useful when only shared reference to cache is available. Returns None if resource is not in cache. Returns Some if resource is in cache.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. If resource is not in cache, it is created and added to the cache. Returns a reference to the resource. Returns error if resource is not in cache and create function fails.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. If resource is not in cache, it is created and added to the cache. Returns a reference to the resource.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. If resource is not in cache, it is created and added to the cache. Returns a reference to the resource.

Fetches resource from cache. Resource last used epoch is updated to the current epoch. If resource is not in cache, it is created and added to the cache. Returns a reference to the resource.

Moves to the next epoch.

Evicts resources that have not been used since specified epoch.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.