libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::HTTPCacheTable Class Reference

#include <HTTPCacheTable.h>

Collaboration diagram for libdap::HTTPCacheTable:
Collaboration graph

Classes

struct  CacheEntry
 

Public Types

using CacheEntries = std::vector<CacheEntry *>
 
using CacheTable = std::vector<CacheEntries>
 

Public Member Functions

void delete_by_hits (int hits)
 Delete all the entries in the cache that have fewer than hits hits.
 
void delete_by_size (unsigned long size)
 Delete all the entries in the cache that are larger than size bytes.
 
void delete_expired_entries (time_t time=0)
 Delete all the expired entries in the cache.
 
unsigned int get_block_size () const
 
std::string get_cache_root () const
 
unsigned long get_current_size () const
 
int get_new_entries () const
 
 HTTPCacheTable ()=delete
 
 HTTPCacheTable (const HTTPCacheTable &)=delete
 
 HTTPCacheTable (const std::string &cache_root, int block_size)
 
void increment_new_entries ()
 
HTTPCacheTableoperator= (const HTTPCacheTable &)=delete
 
void set_block_size (unsigned int sz)
 
void set_cache_root (const std::string &cr)
 
void set_current_size (unsigned long sz)
 
virtual ~HTTPCacheTable ()
 

Friends

class HTTPCacheTest
 

Methods to manipulate instances of CacheEntry.

void delete_all_entries ()
 
void add_entry_to_cache_table (CacheEntry *entry)
 
void remove_entry_from_cache_table (const std::string &url)
 
CacheEntryget_read_locked_entry_from_cache_table (const std::string &url)
 
CacheEntryget_write_locked_entry_from_cache_table (const std::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 std::vector< std::string > &headers)
 
void bind_entry_to_data (CacheEntry *entry, FILE *body)
 
void uncouple_entry_from_data (FILE *body)
 
bool is_locked_read_responses () const
 

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.

void create_location (CacheEntry *entry)
 
void cache_index_write ()
 

Detailed Description

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.

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 66 of file HTTPCacheTable.h.

Member Typedef Documentation

◆ CacheEntries

Definition at line 178 of file HTTPCacheTable.h.

◆ CacheTable

Definition at line 179 of file HTTPCacheTable.h.

Constructor & Destructor Documentation

◆ HTTPCacheTable() [1/3]

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

Definition at line 65 of file HTTPCacheTable.cc.

◆ HTTPCacheTable() [2/3]

libdap::HTTPCacheTable::HTTPCacheTable ( const HTTPCacheTable & )
delete

◆ HTTPCacheTable() [3/3]

libdap::HTTPCacheTable::HTTPCacheTable ( )
delete

◆ ~HTTPCacheTable()

libdap::HTTPCacheTable::~HTTPCacheTable ( )
virtual

Definition at line 74 of file HTTPCacheTable.cc.

Member Function Documentation

◆ add_entry_to_cache_table()

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 380 of file HTTPCacheTable.cc.

◆ bind_entry_to_data()

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

Definition at line 622 of file HTTPCacheTable.cc.

◆ cache_index_write()

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 260 of file HTTPCacheTable.cc.

◆ calculate_time()

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 530 of file HTTPCacheTable.cc.

◆ 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 339 of file HTTPCacheTable.cc.

◆ delete_all_entries()

void libdap::HTTPCacheTable::delete_all_entries ( )

Definition at line 501 of file HTTPCacheTable.cc.

◆ delete_by_hits()

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

Delete all the entries in the cache that have fewer than hits hits.

Parameters
hits

Definition at line 111 of file HTTPCacheTable.cc.

◆ delete_by_size()

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

Delete all the entries in the cache that are larger than size bytes.

Parameters
size

Definition at line 131 of file HTTPCacheTable.cc.

◆ delete_expired_entries()

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

Delete all the expired entries in the cache.

Parameters
tTime to use as the base for the expiration check. If 0, use Now.

Definition at line 87 of file HTTPCacheTable.cc.

◆ get_block_size()

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

Definition at line 215 of file HTTPCacheTable.h.

◆ get_cache_root()

std::string libdap::HTTPCacheTable::get_cache_root ( ) const
inline

Definition at line 223 of file HTTPCacheTable.h.

◆ get_current_size()

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

Definition at line 211 of file HTTPCacheTable.h.

◆ get_new_entries()

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

Definition at line 219 of file HTTPCacheTable.h.

◆ get_read_locked_entry_from_cache_table()

HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::get_read_locked_entry_from_cache_table ( const std::string & url)

Get a pointer to a CacheEntry from the cache table.

Parameters
urlLook for this URL.

Definition at line 400 of file HTTPCacheTable.cc.

◆ get_write_locked_entry_from_cache_table()

HTTPCacheTable::CacheEntry * libdap::HTTPCacheTable::get_write_locked_entry_from_cache_table ( const std::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

Note
The caller must unlock the entry when it is done with it.
Parameters
urlLook for this URL.
Returns
The matching CacheEntry instance or NULL if none was found.

Definition at line 441 of file HTTPCacheTable.cc.

◆ increment_new_entries()

void libdap::HTTPCacheTable::increment_new_entries ( )
inline

Definition at line 221 of file HTTPCacheTable.h.

◆ is_locked_read_responses()

bool libdap::HTTPCacheTable::is_locked_read_responses ( ) const

Definition at line 639 of file HTTPCacheTable.cc.

◆ operator=()

HTTPCacheTable & libdap::HTTPCacheTable::operator= ( const HTTPCacheTable & )
delete

◆ parse_headers()

void libdap::HTTPCacheTable::parse_headers ( HTTPCacheTable::CacheEntry * entry,
unsigned long max_entry_size,
const std::vector< std::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 569 of file HTTPCacheTable.cc.

◆ remove_entry_from_cache_table()

void libdap::HTTPCacheTable::remove_entry_from_cache_table ( const std::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 485 of file HTTPCacheTable.cc.

◆ set_block_size()

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

Definition at line 217 of file HTTPCacheTable.h.

◆ set_cache_root()

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

Definition at line 225 of file HTTPCacheTable.h.

◆ set_current_size()

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

Definition at line 213 of file HTTPCacheTable.h.

◆ uncouple_entry_from_data()

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

Definition at line 627 of file HTTPCacheTable.cc.

Friends And Related Symbol Documentation

◆ HTTPCacheTest

friend class HTTPCacheTest
friend

Definition at line 181 of file HTTPCacheTable.h.


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