PLaSK library
Loading...
Searching...
No Matches
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< Valueget (Key *index)
 Try get object from cache.
 
plask::shared_ptr< Valueget (plask::shared_ptr< Key > index)
 Try get object from cache.
 
plask::shared_ptr< Valueget (Key *index) const
 Try get object from cache.
 
plask::shared_ptr< Valueget (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< Valueoperator() (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< Valueoperator() (Key *index, shared_ptr< Value > value)
 Append cache entry which consists of given index and value and return value.
 
plask::shared_ptr< Valueoperator() (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< Valueoperator() (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
Keytype using as index in cache (pointer to this type will be used), must be able to emit events;
Valuetype for cache values, will be stored in weak_ptr;
deleteStrategywhen cache entries should be deleted:

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
indexkey 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
indexkey 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
indexkey 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
indexkey 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: