Extensible cache templates.
Consider the following scenario:
- You need to generate textures for a game renderer
- The textures can be given unique names so they can be reused
- Eventually each texture won't be needed when the game scene moves on
You need to store the textures in a map
but you need to remove the oldest textures when adding new ones to limit the container size.
This is a sufficiently frequent scenario for a generic template: caches::StoreCache
tracks the least recently used key and allows access by reference:
#include <string>
#include <caches/stores/store_cache.tpp>
class Texture() { ... }
caches::StoreCache<Texture> cache(2);
Texture texture_a;
cache.store("a", texture_a);
Texture texture_b;
cache.store("b", texture_b);
Texture texture_c;
// This pops texture_a
cache.store("c", texture_c);
cache.size() -> 2UL
cache.at("b") -> texture_b
cache.at("c") -> texture_c
conan search caches
You can also download the sources.
Documentation and more detailed examples are hosted on Github Pages.
- First in, first out
- Fixed size cache with generic
T
elements - Access by value with
T next() const
andT last() const
#include <string>
#include <caches/queues/fifo_cache.tpp>
caches::FIFOCache<std::string> cache(2);
First in, first out, with a fixed size:
cache.push("a");
cache.push("b");
cache.push("c");
cache.size() -> 2UL
cache.next() -> "b"
cache.last() -> "c"
- Last in, first out
- Fixed size cache with generic
T
elements - Access by value with
T next() const
andT last() const
#include <string>
#include <caches/queues/lifo_cache.tpp>
caches::LIFOCache<std::string> cache(2);
cache.push("a");
cache.push("b");
cache.push("c");
cache.size() -> 2UL
cache.next() -> "c"
cache.last() -> "b"
- Pops the least recently accessed key
- Fixed size cache of generic
K: V
pairs - Access by value with
operator[](const K &key)
#include <string>
#include <caches/stores/lru_cache.tpp>
caches::LRUCache<std::string, int> cache(2);
cache.store("a", 1);
cache.store("b", 2);
cache.store("c", 3);
cache.size() -> 2UL
cache["b"] -> 2
cache["c"] -> 3
- Pops the least recently accessed key
- Fixed size cache of
string: T
pairs - Access by reference with
T &at(const std::string &key)
#include <string>
#include <caches/stores/store_cache.tpp>
caches::StoreCache<int> cache(2);
cache.store("a", 1);
cache.store("b", 2);
cache.store("c", 3);
cache.size() -> 2UL
cache.at("b") -> 2
cache.at("c") -> 3
To install dependencies:
yarn install
pip install .[all]
conan install .
To run tests:
scons test
To generate the documentation locally:
scons docs
To run linters:
scons lint
To run formatters:
scons format
Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.
This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.
Bump2version is used to version and tag changes. For example:
bump2version patch
- Joel Lefkowitz - Initial work
Lots of love to the open source community!