Template class for a cache that removes items as soon as it exceeds maximum capacity. It uses shared pointers, so items will only be physically deleted once they go out of scope.
#include <Rendering/OpenGL/expirycache.h>
◆ ItemType
◆ PtrType
◆ WeakPtrType
◆ ExpiryCache()
Create a cache with the specified size limit.
◆ ~ExpiryCache()
We ensure the cache is empty, but we don't bother checking whether all of the items are deleted - they will clean themselves up eventually.
◆ capacity()
◆ clear()
◆ contains()
bool contains |
( |
const Key & |
key | ) |
const |
- Parameters
-
key | The key used to find the object in the cache. |
- Returns
- true if the cache contains the object, false otherwise.
◆ count()
◆ insert()
bool insert |
( |
const Key & |
key, |
|
|
const PtrType & |
item, |
|
|
int |
cost = 0 |
|
) |
| |
- Parameters
-
key | The key to associated with the object in the cache. |
item | The item to be stored in the cache. |
cost | The cost associated with the item in the cache. |
- Note
- The cache does not allow duplicate keys. If an item is inserted with a key that is still in use (i.e. a valid pointer to its associated object still remains - in the cache or otherwise),
- Returns
- True if the item could be inserted, false otherwise.
◆ isEmpty()
◆ object()
- Parameters
-
key | The key used to find the object in the cache. |
- Returns
- Attempts to retrieve an item from the cache. If the item doesn't exist in the cache, an invalid pointer is returned. Callers should always test for isNull() on the returned pointer.
◆ operator[]()
◆ setCapacity()
void setCapacity |
( |
int |
capacity | ) |
|
- Parameters
-
capacity | The maximum size of the cache. |
Sets the capacity of the cache; the size after which items will be deleted.
◆ size()
◆ take()
- Parameters
-
key | The key used to find the object in the cache. |
- Returns
- Takes an item out of the cache (removes it), returning it to the user in a pointer. Once the last pointer goes out of scope, the item will be deleted, as it is no inter held by the cache.
◆ totalCost()