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 73 #define LOCK(m) pthread_mutex_lock((m)) 74 #define TRYLOCK(m) pthread_mutex_trylock((m)) 75 #define UNLOCK(m) pthread_mutex_unlock((m)) 76 #define INIT(m) pthread_mutex_init((m), 0) 77 #define DESTROY(m) pthread_mutex_destroy((m)) 142 FILE *d_locked_open_file;
144 bool d_cache_enabled;
145 bool d_cache_protected;
147 bool d_expire_ignored;
148 bool d_always_validate;
150 unsigned long d_total_size;
151 unsigned long d_folder_size;
152 unsigned long d_gc_buffer;
153 unsigned long d_max_entry_size;
154 int d_default_expiration;
156 vector<string> d_cache_control;
166 pthread_mutex_t d_cache_mutex;
171 vector<string> d_open_files;
175 friend class HTTPCacheTest;
180 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
183 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
186 throw InternalErr(__FILE__, __LINE__,
"Unimplemented");
189 HTTPCache(
string cache_root,
bool force);
191 static void delete_instance();
193 void set_cache_root(
const string &root =
"");
194 void create_cache_root(
const string &cache_root);
197 bool get_single_user_lock(
bool force =
false);
198 void release_single_user_lock();
200 bool is_url_in_cache(
const string &url);
204 void write_metadata(
const string &cachename,
const vector<string> &headers);
205 void read_metadata(
const string &cachename, vector<string> &headers);
206 int write_body(
const string &cachename,
const FILE *src);
207 FILE *open_body(
const string &cachename);
210 bool startGC()
const;
212 void perform_garbage_collection();
218 static HTTPCache *instance(
const string &cache_root,
bool force =
false);
221 string get_cache_root()
const;
223 void set_cache_enabled(
bool mode);
224 bool is_cache_enabled()
const;
229 void set_expire_ignored(
bool mode);
230 bool is_expire_ignored()
const;
232 void set_max_size(
unsigned long size);
233 unsigned long get_max_size()
const;
235 void set_max_entry_size(
unsigned long size);
236 unsigned long get_max_entry_size()
const;
238 void set_default_expiration(
int exp_time);
239 int get_default_expiration()
const;
241 void set_always_validate(
bool validate);
242 bool get_always_validate()
const;
244 void set_cache_control(
const vector<string> &cc);
245 vector<string> get_cache_control();
248 DBG(cerr <<
"Locking interface... ");
249 LOCK(&d_cache_mutex);
250 DBGN(cerr <<
"Done" << endl);
253 DBG(cerr <<
"Unlocking interface... " );
255 DBGN(cerr <<
"Done" << endl);
259 bool cache_response(
const string &url, time_t request_time,
260 const vector<string> &headers,
const FILE *body);
261 void update_response(
const string &url, time_t request_time,
262 const vector<string> &headers);
267 bool is_url_valid(
const string &url);
270 vector<string> get_conditional_request_headers(
const string &url);
271 FILE *get_cached_response(
const string &url, vector<string> &headers,
273 FILE *get_cached_response(
const string &url, vector<string> &headers);
274 FILE *get_cached_response(
const string &url);
276 void release_cached_response(FILE *response);
283 #endif // _http_cache_h
A class for software fault reporting.
bool is_hop_by_hop_header(const string &header)
void unlock_cache_interface()
void lock_cache_interface()