39#include "HTTPCacheTable.h"
41#include "HTTPCacheDisconnectedMode.h"
105 FILE *d_locked_open_file;
107 bool d_cache_enabled;
108 bool d_cache_protected;
110 bool d_expire_ignored;
111 bool d_always_validate;
113 unsigned long d_total_size;
114 unsigned long d_folder_size;
115 unsigned long d_gc_buffer;
116 unsigned long d_max_entry_size;
117 int d_default_expiration;
119 vector<string> d_cache_control;
129 pthread_mutex_t d_cache_mutex;
131 HTTPCacheTable *d_http_cache_table;
134 vector<string> d_open_files;
136 static HTTPCache *_instance;
138 friend class HTTPCacheTest;
139 friend class HTTPConnectTest;
141 friend class HTTPCacheInterruptHandler;
144 HTTPCache(
const HTTPCache &);
146 HTTPCache &operator=(
const HTTPCache &);
148 HTTPCache(
string cache_root,
bool force);
150 static void delete_instance();
152 void set_cache_root(
const string &root =
"");
153 void create_cache_root(
const string &cache_root);
156 bool get_single_user_lock(
bool force =
false);
157 void release_single_user_lock();
159 bool is_url_in_cache(
const string &url);
163 void write_metadata(
const string &cachename,
const vector<string> &headers);
164 void read_metadata(
const string &cachename, vector<string> &headers);
165 int write_body(
const string &cachename,
const FILE *src);
166 FILE *open_body(
const string &cachename);
169 bool startGC()
const;
171 void perform_garbage_collection();
177 static HTTPCache *instance(
const string &cache_root,
bool force =
false);
178 virtual ~HTTPCache();
180 string get_cache_root()
const;
182 void set_cache_enabled(
bool mode);
183 bool is_cache_enabled()
const;
185 void set_cache_disconnected(CacheDisconnectedMode mode);
188 void set_expire_ignored(
bool mode);
189 bool is_expire_ignored()
const;
191 void set_max_size(
unsigned long size);
192 unsigned long get_max_size()
const;
194 void set_max_entry_size(
unsigned long size);
195 unsigned long get_max_entry_size()
const;
197 void set_default_expiration(
int exp_time);
198 int get_default_expiration()
const;
200 void set_always_validate(
bool validate);
201 bool get_always_validate()
const;
203 void set_cache_control(
const vector<string> &cc);
204 vector<string> get_cache_control();
206 void lock_cache_interface() {
207 DBG(cerr <<
"Locking interface... ");
208 LOCK(&d_cache_mutex);
209 DBGN(cerr <<
"Done" << endl);
211 void unlock_cache_interface() {
212 DBG(cerr <<
"Unlocking interface... ");
213 UNLOCK(&d_cache_mutex);
214 DBGN(cerr <<
"Done" << endl);
218 bool cache_response(
const string &url, time_t request_time,
const vector<string> &headers,
const FILE *body);
219 void update_response(
const string &url, time_t request_time,
const vector<string> &headers);
224 bool is_url_valid(
const string &url);
227 vector<string> get_conditional_request_headers(
const string &url);
228 FILE *get_cached_response(
const string &url, vector<string> &headers,
string &cacheName);
229 FILE *get_cached_response(
const string &url, vector<string> &headers);
230 FILE *get_cached_response(
const string &url);
232 void release_cached_response(FILE *response);
top level DAP object to house generic methods
bool is_hop_by_hop_header(const string &header)