25 #ifndef _http_cache_table_h 26 #define _http_cache_table_h 43 #include "HTTPCache.h" 50 #ifndef _internalerr_h 51 #include "InternalErr.h" 63 #define LOCK(m) do { \ 64 int code = pthread_mutex_lock((m)); \ 66 throw InternalErr(__FILE__, __LINE__, string("Mutex lock: ") + strerror(code)); \ 70 #define UNLOCK(m) do { \ 71 int code = pthread_mutex_unlock((m)); \ 73 throw InternalErr(__FILE__, __LINE__, string("Mutex unlock: ") + strerror(code)); \ 76 #define TRYLOCK(m) pthread_mutex_trylock((m)) 77 #define INIT(m) pthread_mutex_init((m), 0) 78 #define DESTROY(m) pthread_mutex_destroy((m)) 131 time_t freshness_lifetime;
132 time_t response_time;
133 time_t corrected_initial_age;
135 bool must_revalidate;
139 pthread_mutex_t d_response_lock;
140 pthread_mutex_t d_response_write_lock;
144 friend class HTTPCacheTest;
147 friend class DeleteCacheEntry;
148 friend class WriteOneCacheEntry;
149 friend class DeleteExpired;
150 friend class DeleteByHits;
151 friend class DeleteBySize;
154 string get_cachename()
174 void set_size(
unsigned long sz)
178 time_t get_freshness_lifetime()
180 return freshness_lifetime;
182 time_t get_response_time()
184 return response_time;
186 time_t get_corrected_initial_age()
188 return corrected_initial_age;
190 bool get_must_revalidate()
192 return must_revalidate;
194 void set_no_cache(
bool state)
203 void lock_read_response()
205 DBG(cerr <<
"Try locking read response... (" << hex << &d_response_lock << dec <<
") ");
206 int status = TRYLOCK(&d_response_lock);
209 LOCK(&d_response_write_lock);
210 UNLOCK(&d_response_write_lock);
215 DBGN(cerr <<
"Done" << endl);
219 void unlock_read_response()
223 DBG(cerr <<
"Unlocking read response... (" << hex << &d_response_lock << dec <<
") ");
224 UNLOCK(&d_response_lock); DBGN(cerr <<
"Done" << endl);
228 void lock_write_response()
230 DBG(cerr <<
"locking write response... (" << hex << &d_response_lock << dec <<
") ");
231 LOCK(&d_response_lock);
232 LOCK(&d_response_write_lock); DBGN(cerr <<
"Done" << endl);
235 void unlock_write_response()
237 DBG(cerr <<
"Unlocking write response... (" << hex << &d_response_lock << dec <<
") ");
238 UNLOCK(&d_response_write_lock);
239 UNLOCK(&d_response_lock); DBGN(cerr <<
"Done" << endl);
243 url(
""), hash(-1), hits(0), cachename(
""), etag(
""), lm(-1), expires(-1), date(-1), age(-1), max_age(-1), size(
244 0), range(
false), freshness_lifetime(0), response_time(0), corrected_initial_age(0), must_revalidate(
245 false), no_cache(
false), readers(0)
247 INIT(&d_response_lock);
248 INIT(&d_response_write_lock);
251 url(u), hash(-1), hits(0), cachename(
""), etag(
""), lm(-1), expires(-1), date(-1), age(-1), max_age(-1), size(
252 0), range(
false), freshness_lifetime(0), response_time(0), corrected_initial_age(0), must_revalidate(
253 false), no_cache(
false), readers(0)
255 INIT(&d_response_lock);
256 INIT(&d_response_write_lock);
266 typedef vector<CacheEntry *> CacheEntries;
267 typedef CacheEntries::iterator CacheEntriesIter;
269 typedef CacheEntries **CacheTable;
271 friend class HTTPCacheTest;
274 CacheTable d_cache_table;
277 unsigned int d_block_size;
278 unsigned long d_current_size;
280 string d_cache_index;
283 map<FILE *, HTTPCacheTable::CacheEntry *> d_locked_entries;
290 CacheTable &get_cache_table()
292 return d_cache_table;
295 CacheEntry *get_locked_entry_from_cache_table(
int hash,
const string &url);
302 unsigned long get_current_size()
const 304 return d_current_size;
306 void set_current_size(
unsigned long sz)
311 unsigned int get_block_size()
const 315 void set_block_size(
unsigned int sz)
320 int get_new_entries()
const 322 return d_new_entries;
324 void increment_new_entries()
329 string get_cache_root()
333 void set_cache_root(
const string &cr)
339 void delete_expired_entries(time_t time = 0);
340 void delete_by_hits(
int hits);
341 void delete_by_size(
unsigned int size);
342 void delete_all_entries();
356 CacheEntry *get_locked_entry_from_cache_table(
const string &url);
363 void bind_entry_to_data(
CacheEntry *entry, FILE *body);
364 void uncouple_entry_from_data(FILE *body);
365 bool is_locked_read_responses();
void remove_cache_entry(HTTPCacheTable::CacheEntry *entry)
void create_location(CacheEntry *entry)
void parse_headers(HTTPCacheTable::CacheEntry *entry, unsigned long max_entry_size, const vector< string > &headers)
void add_entry_to_cache_table(CacheEntry *entry)
void calculate_time(HTTPCacheTable::CacheEntry *entry, int default_expiration, time_t request_time)
top level DAP object to house generic methods
int get_hash(const string &url)
CacheEntry * cache_index_parse_line(const char *line)
void remove_entry_from_cache_table(const string &url)
CacheEntry * get_write_locked_entry_from_cache_table(const string &url)
string create_hash_directory(int hash)
bool cache_index_delete()