39 #ifndef _http_cache_table_h
47 #ifndef _internalerr_h
61 #ifndef _response_too_big_err_h
65 #ifndef _http_cache_disconnected_mode_h
69 #ifndef _signal_handler_registered_err_h
136 FILE *d_locked_open_file;
138 bool d_cache_enabled;
139 bool d_cache_protected;
141 bool d_expire_ignored;
142 bool d_always_validate;
144 unsigned long d_total_size;
145 unsigned long d_folder_size;
146 unsigned long d_gc_buffer;
147 unsigned long d_max_entry_size;
148 int d_default_expiration;
150 vector<string> d_cache_control;
160 pthread_mutex_t d_cache_mutex;
165 vector<string> d_open_files;
169 friend class HTTPCacheTest;
174 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
177 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
179 HTTPCache &operator=(
const HTTPCache &) {
180 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
183 HTTPCache(
string cache_root,
bool force);
185 static void delete_instance();
187 void set_cache_root(
const string &root =
"");
188 void create_cache_root(
const string &cache_root);
191 bool get_single_user_lock(
bool force =
false);
192 void release_single_user_lock();
194 bool is_url_in_cache(
const string &url);
198 void write_metadata(
const string &cachename,
const vector<string> &headers);
199 void read_metadata(
const string &cachename, vector<string> &headers);
200 int write_body(
const string &cachename,
const FILE *src);
201 FILE *open_body(
const string &cachename);
204 bool startGC()
const;
206 void perform_garbage_collection();
212 static HTTPCache *instance(
const string &cache_root,
bool force =
false);
213 virtual ~HTTPCache();
215 string get_cache_root()
const;
217 void set_cache_enabled(
bool mode);
218 bool is_cache_enabled()
const;
223 void set_expire_ignored(
bool mode);
224 bool is_expire_ignored()
const;
226 void set_max_size(
unsigned long size);
227 unsigned long get_max_size()
const;
229 void set_max_entry_size(
unsigned long size);
230 unsigned long get_max_entry_size()
const;
232 void set_default_expiration(
int exp_time);
233 int get_default_expiration()
const;
235 void set_always_validate(
bool validate);
236 bool get_always_validate()
const;
238 void set_cache_control(
const vector<string> &cc);
239 vector<string> get_cache_control();
242 DBG(cerr <<
"Locking interface... ");
243 LOCK(&d_cache_mutex);
244 DBGN(cerr <<
"Done" << endl);
247 DBG(cerr <<
"Unlocking interface... " );
249 DBGN(cerr <<
"Done" << endl);
253 bool cache_response(
const string &url, time_t request_time,
254 const vector<string> &headers,
const FILE *body);
255 void update_response(
const string &url, time_t request_time,
256 const vector<string> &headers);
261 bool is_url_valid(
const string &url);
264 vector<string> get_conditional_request_headers(
const string &url);
265 FILE *get_cached_response(
const string &url, vector<string> &headers,
267 FILE *get_cached_response(
const string &url, vector<string> &headers);
268 FILE *get_cached_response(
const string &url);
270 void release_cached_response(FILE *response);
277 #endif // _http_cache_h