|
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 | can_be_cached (libdap::DDS *dds, const std::string &constraint) |
|
virtual bool | create_and_lock (const string &target, int &fd) |
| 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. 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. 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. More...
|
|
virtual string | get_cache_file_name (const string &src, bool mangle=true) |
|
virtual unsigned long long | get_cache_size () |
| Get the cache size. Read the size information from the cache info file and return it. This methods locks the cache. More...
|
|
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. 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) |
|
virtual void | lock_cache_read () |
|
virtual void | lock_cache_write () |
|
virtual void | purge_file (const string &file) |
| Purge a single file from the cache. More...
|
|
virtual void | unlock_and_close (const string &target) |
|
virtual void | unlock_cache () |
|
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...
|
|
|
static bool | dir_exists (const 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 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.
- Note
- If the cache_dir parameter is null, this will return null for the pointer to the singleton and caching is disabled.
- Parameters
-
cache_dir_key | Key to use to get the value of the cache directory. If this is the empty stirng, return null right away. |
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 |
- Returns
- A pointer to a BESDapFunctionResponseCache object
|
static BESDapFunctionResponseCache * | get_instance (const string &cache_dir, const string &prefix, unsigned long long size) |
|
static BESDapFunctionResponseCache * | get_instance () |
|
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.
- Note
- Cache entry collisions: This cache must hold objects that are identified by the combination of a dataset and a constraint expression. The CE can be quite large and contain a number of 'special' characters like '()' and so on. Instead of building cache IDs using a simple concatenation of the dataset and CE, we use the C++ std::hash class to generate a hash code. However, it's possible that two different dataset/CE combinations will have the same hash values. We use a simple collision resolution system where a suffix is appended to the hash value. After a number of collisions, we give up and simply do not cache the response (providing no worse performance than if the cache did not exist - but currently we throw an exception - see load_from_cache and the constant 'max_collisions').
-
Cache entry format: The cache uses a specially formated 'response object' that is more efficient to read and write than a typical DAP2 or DAP4 response object. DAP2 serializes data using network byte order while the cache uses native machine order. DAP4 computes checksums; the cache does not. In addition, each cache entry contains the resource id as its first line so that the correct entry can be identified.
- Author
- ndp, jhrg
Definition at line 72 of file BESDapFunctionResponseCache.h.
DDS * BESDapFunctionResponseCache::get_or_cache_dataset |
( |
libdap::DDS * |
dds, |
|
|
const std::string & |
constraint |
|
) |
| |
|
virtual |
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.
- Note
- This method controls the cache lock, ensuring that the cache is unlocked when it returns.
-
The code that evaluates the function expression (when needed) could be sped up by using a thread to handle the process of writing the DDS to the cache, but this will be complicated until we have shared pointers (because the DDS* could be deleted while the cache code is still writing it).
- Parameters
-
- Returns
Definition at line 297 of file BESDapFunctionResponseCache.cc.
References BESFileLockingCache::get_cache_file_name().