HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_LocalDiskCache Class Reference

A disk cache to store expensive data on a local disk. More...

#include <UT_LocalDiskCache.h>

Public Member Functions

 UT_LocalDiskCache (const char *cache_name, int64 max_item_size, int64 max_item_count)
 
 ~UT_LocalDiskCache ()
 
void clearCache (bool reset_file=true)
 
bool extractFromCache (const UT_LocalDiskCacheKey &key, void *buffer, int64 &buffer_size, bool remove_from_cache=true)
 
void storeInCache (const UT_LocalDiskCacheKey &key, const void *buffer, int64 buffer_size)
 Store in the cache. More...
 
int64 getMemoryUsed () const
 Get memory used. More...
 
int64 getFileSize () const
 Get the file size. More...
 
template<typename T >
void traverseCache (T &task)
 Traverse the cache. More...
 
const UT_CappedCachegetCache () const
 Const access to the cache. More...
 

Detailed Description

A disk cache to store expensive data on a local disk.

In some cases, accessing data can be expensive:

  • Loading over a saturated network
  • An expensive computation This cache provides a means to store this data on disk. The disk file is automatically cleaned up when the program completes.

This cache makes a reasonable secondary cache.

Definition at line 47 of file UT_LocalDiskCache.h.

Constructor & Destructor Documentation

UT_LocalDiskCache::UT_LocalDiskCache ( const char *  cache_name,
int64  max_item_size,
int64  max_item_count 
)

The cache is used to store data in a temporary disk file max_item_size is the maximum size for each item put into the cache max_item_count is the maximum number of items to be stored in the cache It's fairly obvious that the maximum size for the disk file will be max_item_size*max_item_count.

UT_LocalDiskCache::~UT_LocalDiskCache ( )

Member Function Documentation

void UT_LocalDiskCache::clearCache ( bool  reset_file = true)

Clear entire disk cache. This is not thread safe and should only be called when the cache isn't under contention.

bool UT_LocalDiskCache::extractFromCache ( const UT_LocalDiskCacheKey key,
void buffer,
int64 buffer_size,
bool  remove_from_cache = true 
)

Extract from the disk cache. Once extracted, the item will no longer exist in the cache.

The remove_from_cache flag determines whether the object will be removed from the disk cache after extraction. Since this cache is usually used as a secondary cache, it's usually the primary cache which extracts the data from the disk cache (keeping the object in the primary cache after).

const UT_CappedCache& UT_LocalDiskCache::getCache ( ) const
inline

Const access to the cache.

Definition at line 97 of file UT_LocalDiskCache.h.

int64 UT_LocalDiskCache::getFileSize ( ) const
inline

Get the file size.

Definition at line 88 of file UT_LocalDiskCache.h.

int64 UT_LocalDiskCache::getMemoryUsed ( ) const

Get memory used.

void UT_LocalDiskCache::storeInCache ( const UT_LocalDiskCacheKey key,
const void buffer,
int64  buffer_size 
)

Store in the cache.

template<typename T >
void UT_LocalDiskCache::traverseCache ( T task)
inline

Traverse the cache.

Definition at line 91 of file UT_LocalDiskCache.h.


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