#include <UT_LimitedCache.h>

Classes | |
| class | Lookup |
| class | ut_KeyCompare |
| class | ut_StorageTable |
Public Member Functions | |
| UT_LimitedCache (const char *cache_name, int64 size_in_mb=32) | |
| ~UT_LimitedCache () | |
| int64 | entries () const |
| Find out the number of entries being stored in the cache. | |
| int64 | lru_entries () const |
| Find out the number of entries being stored in the cache. | |
| void | clearCache () |
| Clear all elements out of the cache. | |
| Lookup | findItem (const UT_LimitedCacheKey &key) |
| Lookup | addItem (const UT_LimitedCacheKey &key, UT_LimitedCacheItem *item) |
| void | deallocateItem (const UT_LimitedCacheKey &key) |
| void | dumpCache () const |
| Debug and dump the cache -- this may not work properly in threaded code. | |
| Lookup | operator() (const UT_LimitedCacheKey &key) |
| Lookup | operator[] (const UT_LimitedCacheKey &key) |
| virtual const char * | utGetCacheName () const |
| virtual int64 | utGetCurrentSize () |
| virtual bool | utHasMaxSize () const |
| virtual int64 | utGetMaxSize () |
| virtual void | utSetMaxSize (int64 bytes) |
| virtual int64 | utReduceCacheSizeBy (int64 amount) |
Protected Types | |
| typedef UT_ConcurrentHashMap < UT_LimitedCacheKey *, UT_LimitedCacheItem *, ut_KeyCompare > | ut_StorageMap_t |
Friends | |
| class | Lookup |
| typedef ut_StorageMap_t::const_iterator | unsafe_traverser |
| unsafe_traverser | unsafe_begin () const |
| unsafe_traverser | unsafe_end () const |
The memory limited cache allows you to put objects into the cache. The cache will automatically throw objects away based on memory usage. You can put as many objects into the cache as you want, but don't count on always being able to find them in the cache since they may get thrown out.
Example:
class Item : public UT_LimitedCacheItem { public: Item() : UT_LimitedCacheItem() {} virtual ~Item(); Data myData; // Data in item }; class Key : public UT_LimitedCacheKey { Key(const char *str) { myString.harden(str); } Key(const Key &key) { myString.harden(key.myString); } virtual UT_LimitedCacheKey *duplicate() const { return new Key(*this); } virtual unsigned getHash() const { return myString.hash(); } virtual bool isEqual(const UT_LimitedCacheKey &src) const { const Key &k = static_cast<Key &>(src); return k.myString == myString; } virtual int64 getTotalMemory() const { return myString.getMemoryUsage() } sizeof(Item) + sizeof(*this); } }; static bool testLookup(const UT_LimitedCache &cache, const char *str) { UT_LimitedCache::Lookup found; found = cache[Key(str)]; if (found.isValid()) processItem(found.getItem()); } testCache(const UT_StringArray &strings) { UT_LimitedCache cache("Test-Cache", 8); // An 8 MB cache for (int i = 0; i < strings.entries(); i++) cache.addItem(Key(strings(i)), new Item()); testLookup("foo"); testLookup("bar"); }
Definition at line 133 of file UT_LimitedCache.h.
| typedef ut_StorageMap_t::const_iterator UT_LimitedCache::unsafe_traverser |
Thread unsafe traversal of the cache contents
Definition at line 306 of file UT_LimitedCache.h.
typedef UT_ConcurrentHashMap<UT_LimitedCacheKey *, UT_LimitedCacheItem *, ut_KeyCompare> UT_LimitedCache::ut_StorageMap_t [protected] |
Definition at line 292 of file UT_LimitedCache.h.
| UT_LimitedCache::UT_LimitedCache | ( | const char * | cache_name, | |
| int64 | size_in_mb = 32 | |||
| ) |
| UT_LimitedCache::~UT_LimitedCache | ( | ) |
| Lookup UT_LimitedCache::addItem | ( | const UT_LimitedCacheKey & | key, | |
| UT_LimitedCacheItem * | item | |||
| ) |
Add an item to the cache. Due to concurrency, the lookup info returned may not contain the object added. The item passed in may be deleted by this method and should not be used once passed in.
Lookup should be used. | void UT_LimitedCache::clearCache | ( | ) |
Clear all elements out of the cache.
| void UT_LimitedCache::deallocateItem | ( | const UT_LimitedCacheKey & | key | ) |
Forcibly delete an item from the cache. This will delete the item from the LRU cache and the table.
| void UT_LimitedCache::dumpCache | ( | ) | const |
Debug and dump the cache -- this may not work properly in threaded code.
| int64 UT_LimitedCache::entries | ( | void | ) | const [inline] |
Find out the number of entries being stored in the cache.
Definition at line 231 of file UT_LimitedCache.h.
| Lookup UT_LimitedCache::findItem | ( | const UT_LimitedCacheKey & | key | ) |
Find an item in the cache. If there's nothing found, the lookup info returned will be empty.
| int64 UT_LimitedCache::lru_entries | ( | ) | const [inline] |
Find out the number of entries being stored in the cache.
Definition at line 234 of file UT_LimitedCache.h.
| Lookup UT_LimitedCache::operator() | ( | const UT_LimitedCacheKey & | key | ) | [inline] |
Convenience array operators to lookup objects based on the key
Definition at line 224 of file UT_LimitedCache.h.
| Lookup UT_LimitedCache::operator[] | ( | const UT_LimitedCacheKey & | key | ) | [inline] |
Convenience array operators to lookup objects based on the key
Definition at line 226 of file UT_LimitedCache.h.
| unsafe_traverser UT_LimitedCache::unsafe_begin | ( | ) | const [inline] |
Thread unsafe traversal of the cache contents
Definition at line 307 of file UT_LimitedCache.h.
| unsafe_traverser UT_LimitedCache::unsafe_end | ( | ) | const [inline] |
Thread unsafe traversal of the cache contents
Definition at line 308 of file UT_LimitedCache.h.
| virtual const char* UT_LimitedCache::utGetCacheName | ( | ) | const [inline, virtual] |
| virtual int64 UT_LimitedCache::utGetCurrentSize | ( | ) | [inline, virtual] |
| virtual int64 UT_LimitedCache::utGetMaxSize | ( | ) | [inline, virtual] |
API defined on UT_Cache
Reimplemented from UT_Cache.
Definition at line 264 of file UT_LimitedCache.h.
| virtual bool UT_LimitedCache::utHasMaxSize | ( | ) | const [inline, virtual] |
API defined on UT_Cache
Reimplemented from UT_Cache.
Definition at line 262 of file UT_LimitedCache.h.
| virtual void UT_LimitedCache::utSetMaxSize | ( | int64 | bytes | ) | [inline, virtual] |
API defined on UT_Cache
Reimplemented from UT_Cache.
Definition at line 266 of file UT_LimitedCache.h.
friend class Lookup [friend] |
Definition at line 321 of file UT_LimitedCache.h.
1.5.9