libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
|
#include <HTTPCacheTable.h>
Classes | |
struct | CacheEntry |
Public Types | |
typedef vector< CacheEntry * > | CacheEntries |
typedef CacheEntries::iterator | CacheEntriesIter |
typedef CacheEntries ** | CacheTable |
Public Member Functions | |
void | delete_by_hits (int hits) |
void | delete_by_size (unsigned int size) |
void | delete_expired_entries (time_t time=0) |
unsigned int | get_block_size () const |
string | get_cache_root () |
unsigned long | get_current_size () const |
int | get_new_entries () const |
HTTPCacheTable (const string &cache_root, int block_size) | |
void | increment_new_entries () |
void | set_block_size (unsigned int sz) |
void | set_cache_root (const string &cr) |
void | set_current_size (unsigned long sz) |
Cache Index | |
These methods manage the cache's index file. Each cache holds an index file named | |
bool | cache_index_delete () |
bool | cache_index_read () |
CacheEntry * | cache_index_parse_line (const char *line) |
void | cache_index_write () |
string | create_hash_directory (int hash) |
void | create_location (CacheEntry *entry) |
Friends | |
class | HTTPCacheTest |
Methods to manipulate instances of CacheEntry. | |
void | delete_all_entries () |
void | add_entry_to_cache_table (CacheEntry *entry) |
void | remove_cache_entry (HTTPCacheTable::CacheEntry *entry) |
void | remove_entry_from_cache_table (const string &url) |
CacheEntry * | get_locked_entry_from_cache_table (const string &url) |
CacheEntry * | get_write_locked_entry_from_cache_table (const string &url) |
void | calculate_time (HTTPCacheTable::CacheEntry *entry, int default_expiration, time_t request_time) |
void | parse_headers (HTTPCacheTable::CacheEntry *entry, unsigned long max_entry_size, const vector< string > &headers) |
void | bind_entry_to_data (CacheEntry *entry, FILE *body) |
void | uncouple_entry_from_data (FILE *body) |
bool | is_locked_read_responses () |
The table of entries in the client-side cache. This class maintains a table of CacheEntries, where one instance of CacheEntry is made for each item in the cache. When an item is accessed it is either locked for reading or writing. When locked for reading the entry is recorded on a list of read-locked entries. The caller must explicitly free the entry for it to be removed from this list (which is the only way it can be opened for writing). An entry can be accessed by multiple readers but only one writer.
Definition at line 103 of file HTTPCacheTable.h.
typedef vector<CacheEntry *> libdap::HTTPCacheTable::CacheEntries |
Definition at line 228 of file HTTPCacheTable.h.
typedef CacheEntries::iterator libdap::HTTPCacheTable::CacheEntriesIter |
Definition at line 229 of file HTTPCacheTable.h.
typedef CacheEntries** libdap::HTTPCacheTable::CacheTable |
Definition at line 231 of file HTTPCacheTable.h.
libdap::HTTPCacheTable::HTTPCacheTable | ( | const string & | cache_root, |
int | block_size ) |
Definition at line 107 of file HTTPCacheTable.cc.
libdap::HTTPCacheTable::~HTTPCacheTable | ( | ) |
Definition at line 128 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::add_entry_to_cache_table | ( | CacheEntry * | entry | ) |
Add a CacheEntry to the cache table. As each entry is read, load it into the in-memory cache table and update the HTTPCache's current_size. The later is used by the garbage collection method.
entry | The CacheEntry instance to add. |
Definition at line 488 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::bind_entry_to_data | ( | HTTPCacheTable::CacheEntry * | entry, |
FILE * | body ) |
Definition at line 761 of file HTTPCacheTable.cc.
bool libdap::HTTPCacheTable::cache_index_delete | ( | ) |
Remove the cache index file.
A private method.
Definition at line 260 of file HTTPCacheTable.cc.
HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::cache_index_parse_line | ( | const char * | line | ) |
Parse one line of the index file.
A private method.
line | A single line from the .index file. |
line
. Definition at line 305 of file HTTPCacheTable.cc.
bool libdap::HTTPCacheTable::cache_index_read | ( | ) |
Read the saved set of cached entries from disk. Consistency between the in-memory cache and the index is maintained by only reading the index file when the HTTPCache object is created!
A private method.
Definition at line 274 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::cache_index_write | ( | ) |
Walk through the list of cached objects and write the cache index file to disk. If the file does not exist, it is created. If the file does exist, it is overwritten. As a side effect, zero the new_entries counter.
A private method.
Error | Thrown if the index file cannot be opened for writing. |
Definition at line 360 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::calculate_time | ( | HTTPCacheTable::CacheEntry * | entry, |
int | default_expiration, | ||
time_t | request_time ) |
Calculate the corrected_initial_age of the object. We use the time when this function is called as the response_time as this is when we have received the complete response. This may cause a delay if the response header is very big but should not cause any incorrect behavior.
A private method.
entry | The CacheEntry object. |
default_expiration | The default value of the cached object's expiration time. |
request_time | When was the request made? I think this value must be passed into the method that calls this method... |
Definition at line 667 of file HTTPCacheTable.cc.
string libdap::HTTPCacheTable::create_hash_directory | ( | int | hash | ) |
Create the directory path for cache file. The cache uses a set of directories within d_cache_root to store individual responses. The name of the directory that holds a given response is the value returned by the get_hash() function (i.e., it's a number). If the directory exists, this method does nothing.
A private method.
hash | The hash value (i.e., directory name). An integer between 0 and CACHE_TABLE_SIZE (See HTTPCache.h). |
Error | Thrown if the directory cannot be created. |
Definition at line 401 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::create_location | ( | HTTPCacheTable::CacheEntry * | entry | ) |
Create the directory for this url (using the hash value from get_hash()) and a file within that directory to hold the response's information. The cache name and cache_body_fd fields of entry
are updated.
mkstemp opens the file it creates, which is a good thing but it makes tracking resources hard for the HTTPCache object (because an exception might cause a file descriptor resource leak). So I close that file descriptor here.
A private method.
entry | The cache entry object to operate on. |
Error | If the file for the response's body cannot be created. |
Definition at line 436 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::delete_all_entries | ( | ) |
Definition at line 640 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::delete_by_hits | ( | int | hits | ) |
Definition at line 206 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::delete_by_size | ( | unsigned int | size | ) |
Definition at line 237 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::delete_expired_entries | ( | time_t | time = 0 | ) |
Definition at line 172 of file HTTPCacheTable.cc.
|
inline |
Definition at line 264 of file HTTPCacheTable.h.
|
inline |
Definition at line 270 of file HTTPCacheTable.h.
|
inline |
Definition at line 261 of file HTTPCacheTable.h.
HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::get_locked_entry_from_cache_table | ( | const string & | url | ) |
Get a pointer to a CacheEntry from the cache table.
url | Look for this URL. |
Definition at line 511 of file HTTPCacheTable.cc.
|
inline |
Definition at line 267 of file HTTPCacheTable.h.
HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::get_write_locked_entry_from_cache_table | ( | const string & | url | ) |
Get a pointer to a CacheEntry from the cache table. Providing a way to pass the hash code into this method makes it easier to test for correct behavior when two entries collide. 10/07/02 jhrg
url | Look for this URL. |
Definition at line 548 of file HTTPCacheTable.cc.
|
inline |
Definition at line 268 of file HTTPCacheTable.h.
bool libdap::HTTPCacheTable::is_locked_read_responses | ( | ) |
Definition at line 779 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::parse_headers | ( | HTTPCacheTable::CacheEntry * | entry, |
unsigned long | max_entry_size, | ||
const vector< string > & | headers ) |
Parse various headers from the vector (which can be retrieved from libcurl once a response is received) and load the CacheEntry object with values. This method should only be called with headers from a response (it should not be used to parse request headers).
A private method.
entry | Store values from the headers here. |
max_entry_size | DO not cache entries larger than this. |
headers | A vector of header lines. |
Definition at line 706 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::remove_cache_entry | ( | HTTPCacheTable::CacheEntry * | entry | ) |
Remove a CacheEntry. This means delete the entry's files on disk and free the CacheEntry object. The caller should null the entry's pointer in the cache_table. The total size of the cache is decremented once the entry is deleted.
entry | The CacheEntry to delete. |
InternalErr | Thrown if entry is in use. |
Definition at line 572 of file HTTPCacheTable.cc.
void libdap::HTTPCacheTable::remove_entry_from_cache_table | ( | const string & | url | ) |
Find the CacheEntry for the given url and remove both its information in the persistent store and the entry in d_cache_table. If url
is not in the cache, this method does nothing.
url | Remove this URL's entry. |
InternalErr | Thrown if the CacheEntry for url is locked. |
Definition at line 615 of file HTTPCacheTable.cc.
|
inline |
Definition at line 265 of file HTTPCacheTable.h.
|
inline |
Definition at line 271 of file HTTPCacheTable.h.
|
inline |
Definition at line 262 of file HTTPCacheTable.h.
void libdap::HTTPCacheTable::uncouple_entry_from_data | ( | FILE * | body | ) |
Definition at line 766 of file HTTPCacheTable.cc.
|
friend |
Definition at line 233 of file HTTPCacheTable.h.