|
OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
This class is used to cache DAP2 response objects. More...
#include <BESDapResponseCache.h>


Public Member Functions | |
| virtual libdap::DDS * | cache_dataset (libdap::DDS &dds, const std::string &constraint, BESDapResponseBuilder *rb, libdap::ConstraintEvaluator *eval, std::string &cache_token) |
| Get the cached DDS object. More... | |
| virtual bool | cache_too_big (unsigned long long current_size) const |
| look at the cache size; is it too large? Look at the cache size and see if it is too big. More... | |
| virtual bool | create_and_lock (const string &target, int &fd) |
| Create a file in the cache and lock it for write access. More... | |
| virtual void | dump (ostream &strm) const |
| dumps information about this object More... | |
| virtual void | exclusive_to_shared_lock (int fd) |
| Transfer from an exclusive lock to a shared lock. More... | |
| virtual string | get_cache_file_name (const string &src, bool mangle=true) |
| Build the name of file that will holds the uncompressed data from 'src' in the cache. More... | |
| virtual unsigned long long | get_cache_size () |
| Get the cache size. More... | |
| virtual bool | get_read_lock (const string &target, int &fd) |
| Get a read-only lock on the file if it exists. More... | |
| const string | getCacheDirectory () |
| const string | getCacheFilePrefix () |
| virtual bool | getExclusiveLock (string file_name, int &ref_fd) |
| Get an exclusive read/write lock on an existing file. More... | |
| virtual void | lock_cache_read () |
| Get a shared lock on the 'cache info' file. More... | |
| virtual void | lock_cache_write () |
| Get an exclusive lock on the 'cache info' file. More... | |
| virtual void | purge_file (const string &file) |
| Purge a single file from the cache. More... | |
| virtual void | unlock_and_close (const string &target) |
| Unlock the named file. More... | |
| virtual void | unlock_cache () |
| Unlock the cache info file. More... | |
| virtual void | update_and_purge (const string &new_file) |
| Purge files from the cache. More... | |
| virtual unsigned long long | update_cache_info (const string &target) |
| Update the cache info file to include 'target'. More... | |
| virtual | ~BESDapResponseCache () |
Static Public Member Functions | |
| static BESDapResponseCache * | get_instance (const string &cache_dir, const string &prefix, unsigned long long size) |
| Get an instance of the BESDapResponseCache object. More... | |
| static BESDapResponseCache * | get_instance () |
| Get the default instance of the BESDapResponseCache object. More... | |
| static string | getCacheDirFromConfig () |
| static string | getCachePrefixFromConfig () |
| static unsigned long | getCacheSizeFromConfig () |
Static Public Attributes | |
| static const string | PATH_KEY = "DAP.ResponseCache.path" |
| static const string | PREFIX_KEY = "DAP.ResponseCache.prefix" |
| static const string | SIZE_KEY = "DAP.ResponseCache.size" |
Protected Member Functions | |
| BESDapResponseCache (const string &cache_dir, const string &prefix, unsigned long long size) | |
| Protected 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... | |
| void | initialize (const string &cache_dir, const string &prefix, unsigned long long size) |
Friends | |
| class | ResponseCacheTest |
| class | StoredResultTest |
This class is used to cache DAP2 response objects.
Definition at line 46 of file BESDapResponseCache.h.
|
protected |
Protected 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.
| 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 (in MBytes) |
| BESSyntaxUserError | if keys not set, cache dir or prefix empty, size is 0, or if cache dir does not exist. |
Definition at line 157 of file BESDapResponseCache.cc.
|
inlinevirtual |
Definition at line 79 of file BESDapResponseCache.h.
|
virtual |
Get the cached DDS object.
Unlike the DAP2 DDS response, this is a C++ DDS object that holds the response's variables, their attributes and their data. The DDS built by the handlers (but without data) is passed into this method along with an CE evaluator, a ResponseBuilder and a reference to a string. If the DDS has already been cached, the cached copy is read and returned (complete with the attributes and data) and the 'cache_token' value-result parameter is set to a string that should be used with the unlock_and_close() method to release the cache's lock on the response. If the DDS is not in the cache, the response is built, cached, locked and returned. In both cases, the cache-token is used to unlock the entry.
Definition at line 452 of file BESDapResponseCache.cc.
References BESDEBUG, BESFileLockingCache::cache_too_big(), BESFileLockingCache::create_and_lock(), CRLF, BESFileLockingCache::exclusive_to_shared_lock(), BESFileLockingCache::get_cache_file_name(), BESDapResponseBuilder::get_dataset_name(), BESFileLockingCache::get_read_lock(), BESFileLockingCache::purge_file(), BESDapResponseBuilder::serialize_dap2_data_ddx(), BESFileLockingCache::unlock_cache(), BESFileLockingCache::update_and_purge(), and BESFileLockingCache::update_cache_info().
Referenced by BESAsciiTransmit::send_basic_ascii().

|
virtualinherited |
look at the cache size; is it too large? Look at the cache size and see if it is too big.
Definition at line 663 of file BESFileLockingCache.cc.
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), BESUncompressManager3::uncompress(), BESFileLockingCache::update_and_purge(), and BESH4Cache::write_cached_data().
|
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.
| target | The name of the file to make/open/lock |
| fd | Value-result param that holds the file descriptor of the opened file |
| BESBESInternalErroror | if any error except EEXIST is returned by open(2) or if fcntl(2) returns an error. |
Definition at line 476 of file BESFileLockingCache.cc.
References BESDEBUG, BESFileLockingCache::lock_cache_write(), and BESFileLockingCache::unlock_cache().
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), BESUncompressManager3::uncompress(), and BESH4Cache::write_cached_data().

|
virtualinherited |
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.
Reimplemented in BESCache3.
Definition at line 901 of file BESFileLockingCache.cc.
References BESIndent::Indent(), BESIndent::LMarg(), and BESIndent::UnIndent().

|
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.
| fd | The file descriptor that is exclusively locked and which, on exit, will have a shared lock. |
Definition at line 506 of file BESFileLockingCache.cc.
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), and BESUncompressManager3::uncompress().
|
virtualinherited |
Build the name of file that will holds the uncompressed data from 'src' in the cache.
| 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 BESStoredDapResultCache.
Definition at line 407 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), and BESUncompressManager3::uncompress().
|
virtualinherited |
Get the cache size.
Read the size information from the cache info file and return it. This methods locks the cache.
Definition at line 675 of file BESFileLockingCache.cc.
References BESFileLockingCache::lock_cache_read(), and BESFileLockingCache::unlock_cache().
Referenced by BESFileLockingCache::purge_file().

|
static |
Get an instance of the BESDapResponseCache object.
This class is a singleton, so the first call to any of three 'get_instance()' methods makes an instance and subsequent calls return a pointer to that instance.
| cache_dir_key | Key to use to get the value of the cache directory |
| prefix_key | Key for the item/file prefix. Each file added to the cache uses this as a prefix so cached items can be easily identified when /tmp is used for the cache. |
| size_key | How big should the cache be, in megabytes |
Definition at line 174 of file BESDapResponseCache.cc.
References BESDEBUG, and BESError::get_message().

|
static |
Get the default instance of the BESDapResponseCache object.
This will read "TheBESKeys" looking for the values of FUNCTION_CACHE_PATH, FUNCTION_CACHE_PREFIX, an FUNCTION_CACHE_SIZE to initialize the cache.
Definition at line 193 of file BESDapResponseCache.cc.
References BESDEBUG, BESError::get_message(), and getCacheDirFromConfig().
Referenced by BESDapResponseBuilder::responseCache().

|
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.
| src | src file that will be cached eventually |
| target | a value-result parameter set to the resulting cached file |
| 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 448 of file BESFileLockingCache.cc.
References BESDEBUG, BESFileLockingCache::lock_cache_read(), and BESFileLockingCache::unlock_cache().
Referenced by cache_dataset(), BESH4Cache::get_data_from_cache(), gateway::RemoteHttpResource::retrieveResource(), and BESUncompressManager3::uncompress().

|
inherited |
Definition at line 888 of file BESFileLockingCache.cc.
|
static |
Definition at line 104 of file BESDapResponseCache.cc.
References BESDEBUG, BESKeys::get_value(), BESUtil::lowercase(), and TheBESKeys::TheKeys().
Referenced by get_instance().

|
inherited |
Definition at line 884 of file BESFileLockingCache.cc.
|
static |
Definition at line 86 of file BESDapResponseCache.cc.
References BESDEBUG, BESKeys::get_value(), BESUtil::lowercase(), and TheBESKeys::TheKeys().

|
static |
Definition at line 66 of file BESDapResponseCache.cc.
References BESDEBUG, BESKeys::get_value(), and TheBESKeys::TheKeys().

|
virtualinherited |
Get an exclusive read/write lock on an existing file.
| file_name | The name of the file. |
| ref_fp | if successful, the file descriptor of the file on which we have an exclusive read/write lock. |
| Error | is thrown to indicate a number of untoward events. |
Definition at line 201 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by BESFileLockingCache::purge_file().
|
protectedinherited |
Definition at line 86 of file BESFileLockingCache.cc.
|
virtualinherited |
Get a shared lock on the 'cache info' file.
Definition at line 540 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by BESFileLockingCache::get_cache_size(), and BESFileLockingCache::get_read_lock().
|
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.
Definition at line 528 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by BESFileLockingCache::create_and_lock(), BESFileLockingCache::purge_file(), BESFileLockingCache::update_and_purge(), and BESFileLockingCache::update_cache_info().
|
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.
| file | The name of the file to purge. |
Definition at line 842 of file BESFileLockingCache.cc.
References BESDEBUG, BESFileLockingCache::get_cache_size(), BESFileLockingCache::getExclusiveLock(), BESFileLockingCache::lock_cache_write(), and BESFileLockingCache::unlock_cache().
Referenced by cache_dataset(), and BESH4Cache::get_data_from_cache().

|
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().
| file_name | The name of the file to unlock. |
| BESBESInternalErroror |
Definition at line 578 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by BESH4Cache::get_data_from_cache(), BESFileContainer::release(), and BESH4Cache::write_cached_data().
|
virtualinherited |
Unlock the cache info file.
Definition at line 554 of file BESFileLockingCache.cc.
References BESDEBUG.
Referenced by cache_dataset(), BESFileLockingCache::create_and_lock(), BESFileLockingCache::get_cache_size(), BESFileLockingCache::get_read_lock(), BESFileLockingCache::purge_file(), gateway::RemoteHttpResource::retrieveResource(), BESUncompressManager3::uncompress(), BESFileLockingCache::update_and_purge(), and BESFileLockingCache::update_cache_info().
|
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.
| new_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 758 of file BESFileLockingCache.cc.
References BESDEBUG, BESISDEBUG, BESFileLockingCache::cache_too_big(), BESFileLockingCache::lock_cache_write(), and BESFileLockingCache::unlock_cache().
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), BESUncompressManager3::uncompress(), and BESH4Cache::write_cached_data().

|
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.
| target | The name of the file |
Definition at line 621 of file BESFileLockingCache.cc.
References BESDEBUG, BESFileLockingCache::lock_cache_write(), and BESFileLockingCache::unlock_cache().
Referenced by cache_dataset(), gateway::RemoteHttpResource::retrieveResource(), BESUncompressManager3::uncompress(), and BESH4Cache::write_cached_data().

|
friend |
Definition at line 61 of file BESDapResponseCache.h.
|
friend |
Definition at line 62 of file BESDapResponseCache.h.
|
static |
Definition at line 72 of file BESDapResponseCache.h.
|
static |
Definition at line 73 of file BESDapResponseCache.h.
|
static |
Definition at line 74 of file BESDapResponseCache.h.