libdap++ Updated for version 3.8.2

libdap::HTTPCacheTable Class Reference

#include <HTTPCacheTable.h>

Collaboration diagram for libdap::HTTPCacheTable:

List of all members.

Classes

struct  CacheEntry

Public Types

typedef vector< CacheEntry * > CacheEntries
typedef CacheEntries::iterator CacheEntriesIter
typedef CacheEntries ** CacheTable

Public Member Functions

void bind_entry_to_data (CacheEntry *entry, FILE *body)
string create_hash_directory (int hash)
void create_location (CacheEntry *entry)
void delete_by_hits (int hits)
void delete_by_size (unsigned int size)
void delete_expired_entries (time_t time=0)
 HTTPCacheTable (const string &cache_root, int block_size)
bool is_locked_read_responses ()
void uncouple_entry_from_data (FILE *body)
 ~HTTPCacheTable ()
unsigned long get_current_size () const
void set_current_size (unsigned long sz)
unsigned int get_block_size () const
void set_block_size (unsigned int sz)
int get_new_entries () const
void increment_new_entries ()
string get_cache_root ()
void set_cache_root (const string &cr)
Cache Index

These methods manage the cache's index file. Each cache holds an index file named .index which stores the cache's state information.

bool cache_index_delete ()
bool cache_index_read ()
CacheEntrycache_index_parse_line (const char *line)
void cache_index_write ()

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)
CacheEntryget_locked_entry_from_cache_table (const string &url)
CacheEntryget_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)

Detailed Description

The table of entires in the client-side cache. This class maintains a table of CacheEntries, and 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 opended for writing). An entry can be accessed by multiple readers but only one writer.

Note:
The CacheEntry class used to contain a lock that was used to ensure that the entry was locked during any changes to any of its fields. That has been removed - its now the responsibility of the caller. This change was made because it's likely the caller will need to lock all of the methods that operate on a CacheEntry anyway, so the CacheEntry-specific lock was redundant.

Definition at line 81 of file HTTPCacheTable.h.


Member Typedef Documentation

Definition at line 231 of file HTTPCacheTable.h.

typedef CacheEntries::iterator libdap::HTTPCacheTable::CacheEntriesIter

Definition at line 232 of file HTTPCacheTable.h.


Constructor & Destructor Documentation

libdap::HTTPCacheTable::HTTPCacheTable ( const string &  cache_root,
int  block_size 
)

Definition at line 107 of file HTTPCacheTable.cc.

References CACHE_INDEX, cache_index_read(), and CACHE_TABLE_SIZE.

Here is the call graph for this function:

libdap::HTTPCacheTable::~HTTPCacheTable ( )

Definition at line 134 of file HTTPCacheTable.cc.

References CACHE_TABLE_SIZE.


Member Function Documentation

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.

Parameters:
entryThe CacheEntry instance to add.

Definition at line 533 of file HTTPCacheTable.cc.

References DBG, and increment_new_entries().

Referenced by cache_index_read(), and libdap::HTTPCache::cache_response().

Here is the call graph for this function:

void libdap::HTTPCacheTable::bind_entry_to_data ( HTTPCacheTable::CacheEntry entry,
FILE *  body 
)

Definition at line 825 of file HTTPCacheTable.cc.

Referenced by libdap::HTTPCache::get_cached_response().

bool libdap::HTTPCacheTable::cache_index_delete ( )

Remove the cache index file.

A private method.

Returns:
True if the file was deleted, otherwise false.

Definition at line 278 of file HTTPCacheTable.cc.

References REMOVE.

Referenced by delete_all_entries().

HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::cache_index_parse_line ( const char *  line)

Parse one line of the index file.

A private method.

Parameters:
lineA single line from the .index file.
Returns:
A CacheEntry initialized with the information from line.

Definition at line 327 of file HTTPCacheTable.cc.

References CACHE_EMPTY_ETAG.

Referenced by cache_index_read().

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.

Returns:
True when a cache index was found and read, false otherwise.

Definition at line 294 of file HTTPCacheTable.cc.

References add_entry_to_cache_table(), cache_index_parse_line(), DBG, and DBG2.

Referenced by HTTPCacheTable().

Here is the call graph for this function:

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.

Exceptions:
ErrorThrown if the index file cannot be opened for writing.
Note:
The HTTPCache destructor calls this method and silently ignores this exception.

Definition at line 398 of file HTTPCacheTable.cc.

References CACHE_TABLE_SIZE, and DBG.

Referenced by libdap::HTTPCache::cache_response(), libdap::HTTPCache::set_max_entry_size(), libdap::HTTPCache::set_max_size(), and libdap::HTTPCache::~HTTPCache().

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.

Parameters:
entryThe CacheEntry object.
default_expirationThe default value of the cached object's expiration time.
request_timeWhen was the request made? I think this value must be passed into the method that calls this method...

Definition at line 728 of file HTTPCacheTable.cc.

References DBG2, and LM_EXPIRATION.

Referenced by libdap::HTTPCache::cache_response(), and libdap::HTTPCache::update_response().

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.

Parameters:
hashThe hash value (i.e., directory name). An integer between 0 and CACHE_TABLE_SIZE (See HTTPCache.h).
Returns:
The pathname to the directory (even if it already existed).
Exceptions:
ErrorThrown if the directory cannot be created.

Definition at line 443 of file HTTPCacheTable.cc.

References DBG2, and MKDIR.

Referenced by create_location().

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.

Parameters:
entryThe cache entry object to operate on.
Exceptions:
ErrorIf the file for the response's body cannot be created.

Definition at line 481 of file HTTPCacheTable.cc.

References create_hash_directory(), and MKSTEMP.

Referenced by libdap::HTTPCache::cache_response().

Here is the call graph for this function:

void libdap::HTTPCacheTable::delete_all_entries ( )

Definition at line 699 of file HTTPCacheTable.cc.

References cache_index_delete(), and CACHE_TABLE_SIZE.

Referenced by libdap::HTTPCache::purge_cache().

Here is the call graph for this function:

void libdap::HTTPCacheTable::delete_by_hits ( int  hits)

Definition at line 216 of file HTTPCacheTable.cc.

References CACHE_TABLE_SIZE.

void libdap::HTTPCacheTable::delete_by_size ( unsigned int  size)

Definition at line 251 of file HTTPCacheTable.cc.

References CACHE_TABLE_SIZE.

void libdap::HTTPCacheTable::delete_expired_entries ( time_t  time = 0)

Definition at line 179 of file HTTPCacheTable.cc.

References CACHE_TABLE_SIZE.

unsigned int libdap::HTTPCacheTable::get_block_size ( ) const [inline]

Definition at line 274 of file HTTPCacheTable.h.

Referenced by remove_cache_entry().

string libdap::HTTPCacheTable::get_cache_root ( ) [inline]

Definition at line 280 of file HTTPCacheTable.h.

unsigned long libdap::HTTPCacheTable::get_current_size ( ) const [inline]

Definition at line 271 of file HTTPCacheTable.h.

Referenced by remove_cache_entry().

HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::get_locked_entry_from_cache_table ( const string &  url)

Get a pointer to a CacheEntry from the cache table.

Parameters:
urlLook for this URL.

Definition at line 557 of file HTTPCacheTable.cc.

References libdap::get_hash().

Here is the call graph for this function:

int libdap::HTTPCacheTable::get_new_entries ( ) const [inline]

Definition at line 277 of file HTTPCacheTable.h.

Referenced by libdap::HTTPCache::cache_response().

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

Parameters:
urlLook for this URL.
Returns:
The matching CacheEntry instance or NULL if none was found.

Definition at line 596 of file HTTPCacheTable.cc.

References libdap::get_hash().

Referenced by libdap::HTTPCache::update_response().

Here is the call graph for this function:

void libdap::HTTPCacheTable::increment_new_entries ( ) [inline]

Definition at line 278 of file HTTPCacheTable.h.

Referenced by add_entry_to_cache_table().

bool libdap::HTTPCacheTable::is_locked_read_responses ( )

Definition at line 842 of file HTTPCacheTable.cc.

Referenced by libdap::HTTPCache::purge_cache().

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.

Parameters:
entryStore values from the headers here.
max_entry_sizeDO not cache entries larger than this.
headersA vector of header lines.

Definition at line 771 of file HTTPCacheTable.cc.

References DBG2, libdap::parse_time(), and libdap::HTTPCacheTable::CacheEntry::set_no_cache().

Referenced by libdap::HTTPCache::cache_response(), and libdap::HTTPCache::update_response().

Here is the call graph for this function:

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.

Parameters:
entryThe CacheEntry to delete.
Exceptions:
InternalErrThrown if entry is in use.

Definition at line 622 of file HTTPCacheTable.cc.

References CACHE_META, DBG, get_block_size(), get_current_size(), REMOVE, and set_current_size().

Here is the call graph for this function:

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.

Parameters:
urlRemove this URL's entry.
Exceptions:
InternalErrThrown if the CacheEntry for url is locked.

Definition at line 670 of file HTTPCacheTable.cc.

References libdap::get_hash().

Referenced by libdap::HTTPCache::cache_response().

Here is the call graph for this function:

void libdap::HTTPCacheTable::set_block_size ( unsigned int  sz) [inline]

Definition at line 275 of file HTTPCacheTable.h.

void libdap::HTTPCacheTable::set_cache_root ( const string &  cr) [inline]

Definition at line 281 of file HTTPCacheTable.h.

void libdap::HTTPCacheTable::set_current_size ( unsigned long  sz) [inline]

Definition at line 272 of file HTTPCacheTable.h.

Referenced by remove_cache_entry().

void libdap::HTTPCacheTable::uncouple_entry_from_data ( FILE *  body)

Definition at line 830 of file HTTPCacheTable.cc.

References libdap::HTTPCacheTable::CacheEntry::unlock_read_response().

Referenced by libdap::HTTPCache::release_cached_response().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class HTTPCacheTest [friend]

Definition at line 236 of file HTTPCacheTable.h.


The documentation for this class was generated from the following files: