OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
Implementation of a caching mechanism. More...
#include <BESCache.h>
Classes | |
struct | cache_entry |
for filename -> filesize map below More... | |
struct | CacheDirInfo |
Helper class for info on the cache directory. More... | |
Public Types | |
typedef std::multimap< double, cache_entry, std::greater < double > > | CacheFilesByAgeMap |
Sugar for the multimap of entries sorted with older files first. More... | |
Public Member Functions | |
BESCache (const string &cache_dir, const string &prefix, unsigned long long sizeInMegs) | |
Constructor that takes as arguments the values of the cache dir, the file prefix, and the cache size. More... | |
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. More... | |
string | cache_dir () const |
unsigned long long | cache_size () const |
void | collect_cache_dir_info (BESCache::CacheDirInfo &cd_info) const |
virtual void | dump (ostream &strm) const |
dumps information about this object More... | |
virtual bool | is_cached (const string &src, string &target) |
Determine if the file specified by src is cached. More... | |
virtual bool | lock (unsigned int retry_ms, unsigned int num_tries) |
lock the cache using a file lock More... | |
string | match_prefix () const |
string | prefix () const |
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. More... | |
virtual bool | unlock () |
unlock the cache More... | |
virtual | ~BESCache () |
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.
Definition at line 58 of file BESCache.h.
typedef std::multimap<double, cache_entry, std::greater<double> > BESCache::CacheFilesByAgeMap |
Sugar for the multimap of entries sorted with older files first.
Definition at line 71 of file BESCache.h.
BESCache::BESCache | ( | const string & | cache_dir, |
const string & | prefix, | ||
unsigned long long | sizeInMegs | ||
) |
Constructor that takes as arguments the values of the cache dir, the file prefix, and the cache size.
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) |
BESSyntaxUserError | if cache_dir or prefix is empty, if size is 0, or if the cache directory does not exist. |
Definition at line 121 of file BESCache.cc.
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.
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 |
BESSyntaxUserError | if keys not set, cache dir or prefix empty, size is 0, or if cache dir does not exist. |
Definition at line 146 of file BESCache.cc.
References BESKeys::get_value().
|
inlinevirtual |
Definition at line 134 of file BESCache.h.
|
inline |
Definition at line 143 of file BESCache.h.
Referenced by BESUncompressManager::uncompress().
|
inline |
Definition at line 146 of file BESCache.h.
void BESCache::collect_cache_dir_info | ( | BESCache::CacheDirInfo & | cd_info | ) | const |
Definition at line 440 of file BESCache.cc.
References BESCache::CacheDirInfo::_contents, BESCache::CacheDirInfo::_num_files_in_cache, BESCache::CacheDirInfo::_total_cache_files_size, BESCache::CacheDirInfo::clear(), BESCache::cache_entry::name, and BESCache::cache_entry::size.
Referenced by purge().
|
virtual |
dumps information about this object
Displays the pointer value of this instance along with information about this cache.
strm | C++ i/o stream to dump the information to |
Implements BESObj.
Definition at line 504 of file BESCache.cc.
References BESIndent::Indent(), BESIndent::LMarg(), and BESIndent::UnIndent().
|
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.
src | src file that will be cached eventually |
target | set to the resulting cached file |
Definition at line 277 of file BESCache.cc.
Referenced by BESUncompressManager::uncompress().
|
virtual |
lock the cache using a file lock
if the cache has not already been locked, lock it using a file lock.
BESInternalError | if the cache is already locked |
Definition at line 194 of file BESCache.cc.
Referenced by BESUncompressManager::uncompress().
|
inline |
Definition at line 144 of file BESCache.h.
|
inline |
Definition at line 145 of file BESCache.h.
|
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.
Definition at line 324 of file BESCache.cc.
References BESCache::CacheDirInfo::_contents, BESCache::CacheDirInfo::_num_files_in_cache, BESCache::CacheDirInfo::_total_cache_files_size, BESDEBUG, BESISDEBUG, collect_cache_dir_info(), and BESCache::CacheDirInfo::get_avg_size().
Referenced by BESUncompressManager::uncompress().
|
virtual |
unlock the cache
If the cache is locked, unlock it using the stored file lock descriptor
BESInternalError | if the cache is not already locked |
Definition at line 246 of file BESCache.cc.
Referenced by BESUncompressManager::uncompress().