PLaSK library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
plask::WeakCache< Key, Value, DeleteStrategy > Struct Template Reference

Cache values of type Value using Key type to index it. More...

`#include <plask/utils/cache.hpp>`

Inheritance diagram for plask::WeakCache< Key, Value, DeleteStrategy >:
[legend]
Collaboration diagram for plask::WeakCache< Key, Value, DeleteStrategy >:
[legend]

## Public Member Functions
plask::shared_ptr< Value > | get (Key *index)
| Try get object from cache.
plask::shared_ptr< Value > | get (plask::shared_ptr< Key > index)
| Try get object from cache.
plask::shared_ptr< Value > | get (Key *index) const
| Try get object from cache.
plask::shared_ptr< Value > | get (plask::shared_ptr< Key > index) const
| Try get object from cache.
void | cleanDeleted ()
| Clean all entries for which values are already deleted.
Public Member Functions inherited from plask::CacheBase< Key, ValuePtr, DeleteStrategy >
| ~CacheBase ()
| Clear cache.
void | append (Key *index, ValuePtr value)
| Append entry to cache.
void | append (plask::shared_ptr< Key > index, ValuePtr value)
| Append entry to cache.
plask::shared_ptr< Value > | operator() (Key *index, Value *value)
| Construct shared pointer to value and append cache entry which consists of given index and constructed shared pointer.
plask::shared_ptr< Value > | operator() (Key *index, shared_ptr< Value > value)
| Append cache entry which consists of given index and value and return value.
plask::shared_ptr< Value > | operator() (plask::shared_ptr< Key > index, Value *value)
| Construct shared pointer to value and append cache entry which consists of given index and constructed shared pointer.
plask::shared_ptr< Value > | operator() (plask::shared_ptr< Key > index, shared_ptr< Value > value)
| Construct shared pointer to value and append cache entry which consists of given index and constructed shared pointer.
void | clear ()
| Remove all entries from this cache.

## Additional Inherited Members
Public Types inherited from plask::CacheBase< Key, ValuePtr, DeleteStrategy >
typedef ValuePtr::element_type | Value

## Detailed Description

template<typename Key, typename Value, template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>
struct plask::WeakCache< Key, Value, DeleteStrategy >

Cache values of type Value using Key type to index it.

It sores only weak_ptr to values, so it not prevent values from deletion. Cache entries are removed on key changes (see `deleteStrategy`) or when value expires (only at moment of getting from non-const cache or calling cleanDeleted).

Template Parameters

  Key | type using as index in cache (pointer to this type will be used), must be able to emit events;
  Value | type for cache values, will be stored in weak_ptr;
  deleteStrategy | when cache entries should be deleted: CacheRemoveOnlyWhenDeleted - when key is deleted (default), CacheRemoveOnEachChange - when key is changed, other class template which derives from plask::CacheRemoveStrategyBase and have void onEvent(typename Key::Event& evt) method - custom.

Definition at line 211 of file cache.hpp.

## Member Function Documentation

## ◆ cleanDeleted()

template<typename Key , typename Value , template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>

void plask::WeakCache< Key, Value, DeleteStrategy >::cleanDeleted | ( |  | ) |
| inline

Clean all entries for which values are already deleted.

This method has O(N+DlogN) time complexity, where N is number of objects in cache, and D is number of deleted objects.

Definition at line 272 of file cache.hpp.

## ◆ get() [1/4]

template<typename Key , typename Value , template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>

plask::shared_ptr< Value > plask::WeakCache< Key, Value, DeleteStrategy >::get | ( | Key * | index | ) |
| inline

Try get object from cache.

Try also clean entry with `el` index if value for it is not still valid.

Parameters

  index | key of object

Returns
  non-null value from cache stored for key or nullptr if there is no value for given index or value was not valid

Definition at line 220 of file cache.hpp.

## ◆ get() [2/4]

template<typename Key , typename Value , template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>

plask::shared_ptr< Value > plask::WeakCache< Key, Value, DeleteStrategy >::get | ( | Key * | index | ) | const
| inline

Try get object from cache.

Parameters

  index | key of object

Returns
  non-null value from cache stored for key or nullptr if there is no value for given index or value is not valid

Definition at line 249 of file cache.hpp.

## ◆ get() [3/4]

template<typename Key , typename Value , template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>

plask::shared_ptr< Value > plask::WeakCache< Key, Value, DeleteStrategy >::get | ( | plask::shared_ptr< Key > | index | ) |
| inline

Try get object from cache.

Try also clean entry with `el` index if value for it is not still valid.

Parameters

  index | key of object

Returns
  non-null value from cache stored for key or nullptr if there is no value for given index or value was not valid

Definition at line 240 of file cache.hpp.

## ◆ get() [4/4]

template<typename Key , typename Value , template< typename SKey, typename SValuePtr > class DeleteStrategy = CacheRemoveOnlyWhenDeleted>

plask::shared_ptr< Value > plask::WeakCache< Key, Value, DeleteStrategy >::get | ( | plask::shared_ptr< Key > | index | ) | const
| inline

Try get object from cache.

Parameters

  index | key of object

Returns
  non-null value from cache stored for key or nullptr if there is no value for given index or value is not valid

Definition at line 263 of file cache.hpp.

The documentation for this struct was generated from the following file:

- plask/utils/cache.hpp