35 #ifndef IECORE_LRUCACHE_H
36 #define IECORE_LRUCACHE_H
38 #include "boost/noncopyable.hpp"
39 #include "boost/function.hpp"
40 #include "boost/variant.hpp"
45 namespace LRUCachePolicy
52 template<
typename LRUCache>
58 template<
typename LRUCache>
81 template<
typename Key,
typename Value,
template <
typename>
class Policy=
LRUCachePolicy::Parallel,
typename GetterKey=Key>
92 typedef boost::function<Value ( const GetterKey &key, Cost &cost )>
GetterFunction;
94 typedef boost::function<void ( const Key &key, const Value &data )>
RemovalCallback;
97 LRUCache( GetterFunction getter, Cost maxCost );
98 LRUCache( GetterFunction getter, RemovalCallback removalCallback, Cost maxCost );
106 Value
get(
const GetterKey &key );
113 bool set(
const Key &key,
const Value &value, Cost cost );
118 bool cached(
const Key &key )
const;
122 bool erase(
const Key &key );
148 GetterFunction m_getter;
149 RemovalCallback m_removalCallback;
170 typedef boost::variant<boost::blank, Value, std::exception_ptr> State;
175 Status status()
const;
181 Policy<LRUCache> m_policy;
190 bool setInternal(
const Key &key, CacheEntry &cacheEntry,
const Value &value, Cost cost );
194 bool eraseInternal(
const Key &key, CacheEntry &cacheEntry );
198 void limitCost( Cost cost );
200 static void nullRemovalCallback(
const Key &key,
const Value &value );
206 #include "IECore/LRUCache.inl"
208 #endif // IECORE_LRUCACHE_H
Definition: LRUCache.h:82
bool cached(const Key &key) const
bool erase(const Key &key)
void setMaxCost(Cost maxCost)
Cost currentCost() const
Returns the current cost of all cached items.
Cost getMaxCost() const
Returns the maximum cost.
bool set(const Key &key, const Value &value, Cost cost)
boost::function< Value(const GetterKey &key, Cost &cost)> GetterFunction
Definition: LRUCache.h:92
Definition: LRUCache.h:53
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
boost::function< void(const Key &key, const Value &data)> RemovalCallback
The optional RemovalCallback is called whenever an item is discarded from the cache.
Definition: LRUCache.h:94
Definition: LRUCache.h:59