bes Updated for version 3.20.13
|
Cache the results from server functions. More...
#include <BESDapFunctionResponseCache.h>
Public Member Functions | |
bool | cache_enabled () const |
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. | |
virtual bool | can_be_cached (libdap::DDS *dds, const std::string &constraint) |
virtual bool | create_and_lock (const std::string &target, int &fd) |
Create a file in the cache and lock it for write access. | |
void | disable () |
Disable the cache. | |
virtual void | dump (std::ostream &strm) const |
dumps information about this object | |
void | enable () |
Enable the cache. | |
virtual void | exclusive_to_shared_lock (int fd) |
Transfer from an exclusive lock to a shared lock. | |
const std::string | get_cache_directory () |
virtual std::string | get_cache_file_name (const std::string &src, bool mangle=true) |
const std::string | get_cache_file_prefix () |
virtual unsigned long long | get_cache_size () |
Get the cache size. | |
virtual bool | get_exclusive_lock (const std::string &target, int &fd) |
virtual bool | get_exclusive_lock_nb (const std::string &target, int &fd) |
virtual libdap::DDS * | get_or_cache_dataset (libdap::DDS *dds, const std::string &constraint) |
Return a DDS loaded with data that can be serialized back to a client. | |
virtual bool | get_read_lock (const std::string &target, int &fd) |
Get a read-only lock on the file if it exists. | |
void | initialize (const std::string &cache_dir, const std::string &prefix, unsigned long long size) |
Initialize an instance of FileLockingCache. | |
bool | is_unlimited () const |
Is this cache allowed to store as much as it wants? | |
virtual void | lock_cache_read () |
virtual void | lock_cache_write () |
virtual void | purge_file (const std::string &file) |
Purge a single file from the cache. | |
virtual void | unlock_and_close (const std::string &target) |
virtual void | unlock_cache () |
virtual void | update_and_purge (const std::string &new_file) |
Purge files from the cache. | |
virtual unsigned long long | update_cache_info (const std::string &target) |
Update the cache info file to include 'target'. | |
Static Public Member Functions | |||||||
static bool | dir_exists (const std::string &dir) | ||||||
static string | get_cache_dir_from_config () | ||||||
static string | get_cache_prefix_from_config () | ||||||
static unsigned long | get_cache_size_from_config () | ||||||
Get the singleton instance | |||||||
Get an instance of the BESDapFunctionResponseCache 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.
| |||||||
static BESDapFunctionResponseCache * | get_instance (const std::string &cache_dir, const std::string &prefix, unsigned long long size) | ||||||
static BESDapFunctionResponseCache * | get_instance () | ||||||
Static Public Attributes | |
static const std::string | PATH_KEY = "DAP.FunctionResponseCache.path" |
static const std::string | PREFIX_KEY = "DAP.FunctionResponseCache.prefix" |
static const std::string | SIZE_KEY = "DAP.FunctionResponseCache.size" |
Protected Member Functions | |
BESDapFunctionResponseCache (const std::string &cache_dir, const std::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. | |
Friends | |
class | FunctionResponseCacheTest |
class | StoredResultTest |
Cache the results from server functions.
Serve-side functions build new datasets and can be quite large. This code caches those results so that when clients ask for a suite of responses from the function calls, the computations are run only once (in the best case) and subsequent requests for data or metadata are satisfied using information in this case.
Definition at line 72 of file BESDapFunctionResponseCache.h.
|
inlineprotected |
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 123 of file BESDapFunctionResponseCache.h.
|
inlinevirtual |
Definition at line 137 of file BESDapFunctionResponseCache.h.
|
inlineinherited |
Definition at line 198 of file BESFileLockingCache.h.
|
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 772 of file BESFileLockingCache.cc.
|
virtual |
Definition at line 270 of file BESDapFunctionResponseCache.cc.
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 592 of file BESFileLockingCache.cc.
|
staticinherited |
Does the directory exist?
dir | The pathname to test. |
Definition at line 1121 of file BESFileLockingCache.cc.
|
inlineinherited |
Disable the cache.
Definition at line 204 of file BESFileLockingCache.h.
|
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.
Definition at line 1136 of file BESFileLockingCache.cc.
|
inlineinherited |
Enable the cache.
Definition at line 210 of file BESFileLockingCache.h.
|
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 622 of file BESFileLockingCache.cc.
|
static |
Definition at line 132 of file BESDapFunctionResponseCache.cc.
|
inlineinherited |
Definition at line 188 of file BESFileLockingCache.h.
|
virtualinherited |
Returns the fully qualified file system path name for the cache file associated with this particular cache resource.
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 BESUncompressCache, and http::HttpCache.
Definition at line 444 of file BESFileLockingCache.cc.
|
inlineinherited |
Definition at line 182 of file BESFileLockingCache.h.
|
static |
Definition at line 117 of file BESDapFunctionResponseCache.cc.
|
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 784 of file BESFileLockingCache.cc.
|
static |
Definition at line 101 of file BESDapFunctionResponseCache.cc.
|
virtualinherited |
A blocking call to get an exclusive (write) lock on a file in the cache. Because this cache uses per-process advisory locking, it's possible to call this several times from within a single process and get a lock each time.
file_name | Name of the file to lock |
ref_fd | Return value parameter that holds the file descriptor that is locked. |
BESInternalError | is thrown on any condition other than the file not existing |
Definition at line 1024 of file BESFileLockingCache.cc.
|
virtualinherited |
A non-blocking call to get an exclusive (write) lock on a file in the cache. Because this cache uses per-process advisory locking, it's possible to call this several times from within a single process and get a lock each time.
file_name | Name of the file to lock |
ref_fd | Return value parameter that holds the file descriptor that is locked. |
BESInternalError | is thrown on any condition other than the file not existing or the lock being unavailable. |
Definition at line 870 of file BESFileLockingCache.cc.
|
static |
Definition at line 193 of file BESDapFunctionResponseCache.cc.
|
static |
Definition at line 164 of file BESDapFunctionResponseCache.cc.
|
virtual |
Return a DDS loaded with data that can be serialized back to a client.
Given a DDS and a DAP2 constraint expression that contains only projection function calls, either pull a cached DDS* that is the result of evaluating those functions, or evaluate, cache and return the result. This is the main API cacll for this class.
dds | |
constraint | |
eval |
Definition at line 320 of file BESDapFunctionResponseCache.cc.
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.
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. |
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 537 of file BESFileLockingCache.cc.
|
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.
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 |
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.
|
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.
Definition at line 177 of file BESFileLockingCache.h.
|
virtualinherited |
Get a shared lock on the 'cache info' file.
Definition at line 661 of file BESFileLockingCache.cc.
|
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 646 of file BESFileLockingCache.cc.
|
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 1070 of file BESFileLockingCache.cc.
|
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 705 of file BESFileLockingCache.cc.
|
virtualinherited |
Unlock the cache info file.
Definition at line 678 of file BESFileLockingCache.cc.
|
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 | 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 927 of file BESFileLockingCache.cc.
|
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 729 of file BESFileLockingCache.cc.
|
friend |
Definition at line 105 of file BESDapFunctionResponseCache.h.
|
friend |
Definition at line 106 of file BESDapFunctionResponseCache.h.
|
static |
Definition at line 129 of file BESDapFunctionResponseCache.h.
|
static |
Definition at line 130 of file BESDapFunctionResponseCache.h.
|
static |
Definition at line 131 of file BESDapFunctionResponseCache.h.