BESCache Class Reference

Implementation of a caching mechanism. More...

#include <BESCache.h>

Inheritance diagram for BESCache:

Inheritance graph
[legend]
Collaboration diagram for BESCache:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 BESCache (const string &cache_dir, const string &prefix, unsigned int size)
 Constructor that takes as arguments the values of the cache dir, the file prefix, and the cache size.
 BESCache (BESKeys &keys, const string &cache_dir_key, const string &prefix_key, const string &size_key)
 Constructor that takes as arguments keys to the cache directory, file prefix, and size of the cache to be looked up a configuration file.
virtual ~BESCache ()
virtual bool lock (unsigned int retry_ms, unsigned int num_tries)
 lock the cache using a file lock
virtual bool unlock ()
 unlock the cache
virtual bool is_cached (const string &src, string &target)
 Determine if the file specified by src is cached.
virtual void purge ()
 Check to see if the cache size exceeds the size specified in the constructor and purge older files until size is less.
string cache_dir ()
string prefix ()
unsigned int cache_size ()
virtual void dump (ostream &strm) const
 dumps information about this object


Detailed Description

Implementation of a caching mechanism.

The caching mechanism simply allows the user to create a cache. Cached files are typically specified by full path. The file name is changed by changing all slashes to pound signs (#), the ending extension is removed, and the specified prefix is prepended to the name of the cached file.

The purge method removes the oldest accessed files until the size of all files is less than that specified by the size in the constructors.


Constructor & Destructor Documentation

BESCache::BESCache ( const string &  cache_dir,
const string &  prefix,
unsigned int  size 
)

Constructor that takes as arguments the values of the cache dir, the file prefix, and the cache size.

Parameters:
cache_dir directory where the files are cached
prefix prefix used to prepend to the resulting cached file
size cache max size in megabytes (1 == 1048576 bytes)
Exceptions:
BESInternalError if cache_dir or prefix is empty, if size is 0, or if the cache directory does not exist.

BESCache::BESCache ( BESKeys keys,
const string &  cache_dir_key,
const string &  prefix_key,
const string &  size_key 
)

Constructor that takes as arguments keys to the cache directory, file prefix, and size of the cache to be looked up a configuration file.

The keys specified are looked up in the specified keys object. If not found or not set correctly then an exception is thrown. I.E., if the cache directory is empty, the size is zero, or the prefix is empty.

Parameters:
keys BESKeys object used to look up the keys
cache_dir_key key to look up in the keys file to find cache dir
prefix_key key to look up in the keys file to find the cache prefix
size_key key to look up in the keys file to find the cache size
Exceptions:
BESInternalError if keys not set, cache dir or prefix empty, size is 0, or if cache dir does not exist.

References BESKeys::get_key().

Here is the call graph for this function:

virtual BESCache::~BESCache (  )  [inline, virtual]


Member Function Documentation

bool BESCache::lock ( unsigned int  retry,
unsigned int  num_tries 
) [virtual]

lock the cache using a file lock

if the cache has not already been locked, lock it using a file lock.

Exceptions:
BESInternalError if the cache is already locked

References MAX_LOCK_RETRY_MS, and MAX_LOCK_TRIES.

Referenced by BESUncompressManager::uncompress().

bool BESCache::unlock (  )  [virtual]

unlock the cache

If the cache is locked, unlock it using the stored file lock descriptor

Exceptions:
BESInternalError if the cache is not already locked

Referenced by BESUncompressManager::uncompress().

bool BESCache::is_cached ( const string &  src,
string &  target 
) [virtual]

Determine if the file specified by src is cached.

The src is the full name of the file to be cached. We are assuming that the file name passed has an extension on the end that will be stripped once the file is cached. In other words, if the full path to the file name is /usr/lib/data/fnoc1.nc.gz (a compressed netcdf file) then the resulting file name set in target will be set to #<prefix>#usr#lib#data#fnoc1.nc.

Parameters:
src src file that will be cached eventually
target set to the resulting cached file
Returns:
true if the file is cached already

References BES_CACHE_CHAR.

Referenced by BESUncompressManager::uncompress().

void BESCache::purge (  )  [virtual]

Check to see if the cache size exceeds the size specified in the constructor and purge older files until size is less.

Usually called prior to caching a new file, this method will purge any files, oldest to newest, if the current size of the cache exceeds the size of the cache specified in the constructor.

References BES_CACHE_CHAR, BESDEBUG, BESISDEBUG, _cache_entry::name, and _cache_entry::size.

Referenced by BESUncompressManager::uncompress().

string BESCache::cache_dir (  )  [inline]

string BESCache::prefix (  )  [inline]

unsigned int BESCache::cache_size (  )  [inline]

void BESCache::dump ( ostream &  strm  )  const [virtual]

dumps information about this object

Displays the pointer value of this instance along with information about this cache.

Parameters:
strm C++ i/o stream to dump the information to

Implements BESObj.

References BESIndent::Indent(), BESIndent::LMarg(), and BESIndent::UnIndent().

Here is the call graph for this function:


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

Generated on Wed Sep 24 12:24:38 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.6