#include <BESStoredDapResultCache.h>
|
static const string | PREFIX_KEY = "DAP.StoredResultsCache.prefix" |
|
static const string | SIZE_KEY = "DAP.StoredResultsCache.size" |
|
static const string | SUBDIR_KEY = "DAP.StoredResultsCache.subdir" |
|
|
| BESStoredDapResultCache (const string &data_root_dir, const string &stored_results_subdir, const string &prefix, unsigned long long size) |
|
|
class | ResponseBuilderTest |
|
class | StoredDap2ResultTest |
|
class | StoredDap4ResultTest |
|
This class is used to cache DAP2 response objects.
- Author
- jhrg 5/3/13
Definition at line 52 of file BESStoredDapResultCache.h.
◆ cache_enabled()
bool BESFileLockingCache::cache_enabled |
( |
| ) |
const |
|
inlineinherited |
◆ cache_too_big()
bool BESFileLockingCache::cache_too_big |
( |
unsigned long long |
current_size | ) |
const |
|
virtualinherited |
look at the cache size; is it too large? Look at the cache size and see if it is too big.
- Returns
- True if the size is too big, false otherwise.
Definition at line 778 of file BESFileLockingCache.cc.
◆ create_and_lock()
bool BESFileLockingCache::create_and_lock |
( |
const std::string & |
target, |
|
|
int & |
fd |
|
) |
| |
|
virtualinherited |
Create a file in the cache and lock it for write access.
If the file does not exist, make it, open it for read-write access and get an exclusive lock on it. The locking operation blocks, although that should never happen.
- Parameters
-
target | The name of the file to make/open/lock |
fd | Value-result param that holds the file descriptor of the opened file |
- Returns
- True if the operation was successful, false otherwise. This method will return false if the file already existed (the file won't be locked and the descriptor reference is undefined - but likely -1).
- Exceptions
-
BESBESInternalErroror | if any error except EEXIST is returned by open(2) or if fcntl(2) returns an error. |
Definition at line 597 of file BESFileLockingCache.cc.
◆ dir_exists()
bool BESFileLockingCache::dir_exists |
( |
const std::string & |
dir | ) |
|
|
staticinherited |
Does the directory exist?
- Note
- This is a static method, so it can be called from other static methods like those that build instances of singletons.
- Parameters
-
- Returns
- True if the directory exists, false otherwise
Definition at line 1123 of file BESFileLockingCache.cc.
◆ disable()
void BESFileLockingCache::disable |
( |
| ) |
|
|
inlineinherited |
◆ dump()
void BESFileLockingCache::dump |
( |
ostream & |
strm | ) |
const |
|
virtualinherited |
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.
Definition at line 1138 of file BESFileLockingCache.cc.
◆ enable()
void BESFileLockingCache::enable |
( |
| ) |
|
|
inlineinherited |
◆ exclusive_to_shared_lock()
void BESFileLockingCache::exclusive_to_shared_lock |
( |
int |
fd | ) |
|
|
virtualinherited |
Transfer from an exclusive lock to a shared lock.
If the file has an exclusive write lock on it, change that to a shared read lock. This is an atomic operation. If the call to fcntl(2) is protected by locking the cache, a dead lock will result given typical use of this class. This method exists to help with the situation where one process has the cache locked and is blocking on a shared read lock for a file that a second process has locked exclusively (for writing). By changing the exclusive lock to a shared lock, the first process can get its shared lock and then release the cache.
- Parameters
-
fd | The file descriptor that is exclusively locked and which, on exit, will have a shared lock. |
Definition at line 628 of file BESFileLockingCache.cc.
◆ get_cache_directory()
const std::string BESFileLockingCache::get_cache_directory |
( |
| ) |
|
|
inlineinherited |
◆ get_cache_file_name()
string BESFileLockingCache::get_cache_file_name |
( |
const std::string & |
src, |
|
|
bool |
mangle = true |
|
) |
| |
|
virtualinherited |
Returns the fully qualified file system path name for the cache file associated with this particular cache resource.
- Note
- How names are mangled: ALl occurrences of the characters '<', '>', '=', ',', '/', '(', ')', '"', ''', ':', '?', and ' ' with the '#' character.
- Parameters
-
src | The source name to cache |
mangle | If True, assume the name is a file pathname and mangle it. If false, do not mangle the name (assume the caller has sent a suitable string) but do turn the string into a pathname located in the cache directory with the cache prefix. The 'mangle' param is true by default. |
Reimplemented in cmr::CmrCache, httpd_catalog::RemoteHttpResourceCache, and BESUncompressCache.
Definition at line 448 of file BESFileLockingCache.cc.
◆ get_cache_file_prefix()
const std::string BESFileLockingCache::get_cache_file_prefix |
( |
| ) |
|
|
inlineinherited |
◆ get_cache_size()
unsigned long long BESFileLockingCache::get_cache_size |
( |
| ) |
|
|
virtualinherited |
Get the cache size.
Read the size information from the cache info file and return it. This methods locks the cache.
- Returns
- The size of the cache.
Definition at line 790 of file BESFileLockingCache.cc.
◆ get_cached_dap4_data()
DMR * BESStoredDapResultCache::get_cached_dap4_data |
( |
const string & |
cache_file_name, |
|
|
libdap::D4BaseTypeFactory * |
factory, |
|
|
const string & |
filename |
|
) |
| |
Read data from cache. Allocates a new DDS using the given factory. If the file does not exists this will return null (0).
Definition at line 538 of file BESStoredDapResultCache.cc.
◆ get_instance()
◆ get_read_lock()
bool BESFileLockingCache::get_read_lock |
( |
const std::string & |
target, |
|
|
int & |
fd |
|
) |
| |
|
virtualinherited |
Get a read-only lock on the file if it exists.
Try to get a read-only lock on the file, blocking until we can get it. If the file does not exist, return false.
- Note
- If this code returns false, that means the file did not exist in the cache at the time of the test. by the time the caller gets the result, the file may have been added to the cache by another process.
- Parameters
-
target | The path of the cached file |
fd | A value-result parameter set to the locked cached file. Undefined if the file could not be locked for read access. |
- Returns
- true if the file is in the cache and has been locked, false if the file is/was not in the cache.
- Exceptions
-
Error | if the attempt to get the (shared) lock failed for any reason other than that the file does/did not exist. |
Definition at line 542 of file BESFileLockingCache.cc.
◆ initialize()
void BESFileLockingCache::initialize |
( |
const std::string & |
cache_dir, |
|
|
const std::string & |
prefix, |
|
|
unsigned long long |
size |
|
) |
| |
|
inherited |
Initialize an instance of FileLockingCache.
Initialize and instance of FileLockingCache using the passed values for the cache directory, item prefix and max cache size. This will ignore the value of enable_cache() (but will correctly (re)set it based on the directory, ..., values). This provides a way for clients to re-initialize caches on the fly.
- Parameters
-
cache_dir | The directory into which the cache files will be written. |
prefix | The prefix that will be added to each cache file. |
size | The size of the cache in MBytes |
- Exceptions
-
BESInternalError | If the cache_dir does not exist or is not writable. size is 0, or if cache dir does not exist. |
BESError | If the parameters (directory, ...) are invalid. |
Definition at line 116 of file BESFileLockingCache.cc.
◆ is_unlimited()
bool BESFileLockingCache::is_unlimited |
( |
| ) |
const |
|
inlineinherited |
Is this cache allowed to store as much as it wants?
If the size of the cache is zero bytes, then it is allowed to grow with out bounds.
- Returns
- True if the cache is unlimited in size, false if values will be purged after a preset size is exceeded.
Definition at line 173 of file BESFileLockingCache.h.
◆ lock_cache_read()
void BESFileLockingCache::lock_cache_read |
( |
| ) |
|
|
virtualinherited |
◆ lock_cache_write()
void BESFileLockingCache::lock_cache_write |
( |
| ) |
|
|
virtualinherited |
Get an exclusive lock on the 'cache info' file. The 'cache info' file is used to control certain cache actions, ensuring that they are atomic. These include making sure that the create_and_lock() and read_and_lock() operations are atomic as well as the purge and related operations.
- Note
- This is intended to be used internally only but might be useful in some settings.
Definition at line 652 of file BESFileLockingCache.cc.
◆ purge_file()
void BESFileLockingCache::purge_file |
( |
const std::string & |
file | ) |
|
|
virtualinherited |
Purge a single file from the cache.
Purge a single file from the cache. The file might be old, etc., and need to be removed. Don't use this to shrink the cache when it gets too big, use update_and_purge() instead since that file optimizes accesses to the cache control file for several changes in a row.
- Parameters
-
file | The name of the file to purge. |
Definition at line 1072 of file BESFileLockingCache.cc.
◆ store_dap4_result()
string BESStoredDapResultCache::store_dap4_result |
( |
libdap::DMR & |
dmr, |
|
|
const string & |
constraint, |
|
|
BESDapResponseBuilder * |
rb |
|
) |
| |
|
virtual |
◆ unlock_and_close()
void BESFileLockingCache::unlock_and_close |
( |
const std::string & |
target | ) |
|
|
virtualinherited |
Unlock the named file.
This does not do any name mangling; it just closes and unlocks whatever is named (or throws BESBESInternalErroror if the file cannot be closed). If the file was opened more than once, all descriptors are closed. If you need to close a specific descriptor, use the other version of unlock_and_close().
- Note
- This method assumes that the file was opened/locked using one of read_and_lock() or create_and_lock(). Those methods record the name/file- descriptor pairs so that the files can be properly closed and locks released.
- Parameters
-
file_name | The name of the file to unlock. |
- Exceptions
-
Definition at line 711 of file BESFileLockingCache.cc.
◆ unlock_cache()
void BESFileLockingCache::unlock_cache |
( |
| ) |
|
|
virtualinherited |
Unlock the cache info file.
- Note
- This is intended to be used internally only but might be useful in some settings.
Definition at line 684 of file BESFileLockingCache.cc.
◆ update_and_purge()
void BESFileLockingCache::update_and_purge |
( |
const std::string & |
new_file | ) |
|
|
virtualinherited |
Purge files from the cache.
Purge files, oldest to newest, if the current size of the cache exceeds the size of the cache specified in the constructor. This method uses an exclusive lock on the cache for the duration of the purge process.
- Note
- If the cache size in bytes is zero, calling this method has no affect (the cache is unlimited in size). Other public methods like update_cache_info() and get_cache_size() still work, however.
- Parameters
-
new_file | Do not delete this file. The name of a file this process just added to the cache. Using fcntl(2) locking there is no way this process can detect its own lock, so the shared read lock on the new file won't keep this process from deleting it (but will keep other processes from deleting it). |
Definition at line 932 of file BESFileLockingCache.cc.
◆ update_cache_info()
unsigned long long BESFileLockingCache::update_cache_info |
( |
const std::string & |
target | ) |
|
|
virtualinherited |
Update the cache info file to include 'target'.
Add the size of the named file to the total cache size recorded in the cache info file. The cache info file is exclusively locked by this method for its duration. This updates the cache info file and returns the new size.
- Parameters
-
target | The name of the file |
- Returns
- The new size of the cache
Definition at line 735 of file BESFileLockingCache.cc.
The documentation for this class was generated from the following files: