2018-10-14 17:11:45 +08:00
|
|
|
#pragma once
|
|
|
|
|
#include <event2/event.h>
|
|
|
|
|
#include <event2/buffer.h>
|
|
|
|
|
#include <tfe_future.h>
|
2023-03-30 19:39:18 +08:00
|
|
|
#include <MESA/maat.h>
|
2018-10-14 17:11:45 +08:00
|
|
|
|
2018-11-19 18:37:11 +08:00
|
|
|
|
2018-10-14 17:11:45 +08:00
|
|
|
struct cache_handle;
|
2023-03-30 19:39:18 +08:00
|
|
|
struct cache_handle* create_web_cache_handle(const char* profile_path, const char* section,
|
|
|
|
|
struct event_base* gc_evbase, struct maat *feather, void *logger);
|
2018-11-13 11:56:41 +08:00
|
|
|
|
2018-10-14 17:11:45 +08:00
|
|
|
struct cached_meta
|
|
|
|
|
{
|
2018-10-15 18:37:32 +08:00
|
|
|
size_t content_length;
|
2018-10-14 18:45:02 +08:00
|
|
|
char* content_type;
|
2018-10-25 18:45:33 +08:00
|
|
|
char* last_modified;
|
|
|
|
|
char* etag;
|
2018-10-14 17:11:45 +08:00
|
|
|
};
|
2018-10-25 18:45:33 +08:00
|
|
|
const struct cached_meta* cache_query_result_read_meta(future_result_t * result);
|
2018-10-16 16:51:15 +08:00
|
|
|
size_t cache_query_result_get_data(future_result_t * result, const unsigned char** pp_data);
|
2018-10-14 17:11:45 +08:00
|
|
|
|
2018-11-25 16:32:35 +08:00
|
|
|
int web_cache_async_read(struct cache_handle* handle, unsigned int thread_id,
|
2018-11-13 11:56:41 +08:00
|
|
|
const struct tfe_http_half * request, struct cache_mid** mid, struct future* f);
|
|
|
|
|
|
2018-10-25 18:45:33 +08:00
|
|
|
|
|
|
|
|
|
2018-10-15 18:21:04 +08:00
|
|
|
enum cache_query_result_type
|
|
|
|
|
{
|
|
|
|
|
CACHE_QUERY_RESULT_MISS,
|
|
|
|
|
CACHE_QUERY_RESULT_META,
|
|
|
|
|
CACHE_QUERY_RESULT_DATA,
|
|
|
|
|
CACHE_QUERY_RESULT_END,
|
|
|
|
|
CACHE_QUERY_RESULT_IRRELEVANT,
|
|
|
|
|
__CACHE_QUERY_RESULT_MAX
|
|
|
|
|
};
|
|
|
|
|
enum cache_query_result_type cache_query_result_get_type(future_result_t * result);
|
2018-10-14 17:11:45 +08:00
|
|
|
|
2018-10-25 18:45:33 +08:00
|
|
|
enum cache_pending_result
|
|
|
|
|
{
|
|
|
|
|
PENDING_RESULT_NONE=0,
|
|
|
|
|
PENDING_RESULT_FOBIDDEN,
|
|
|
|
|
PENDING_RESULT_REVALIDATE,
|
|
|
|
|
PENDING_RESULT_ALLOWED,
|
2018-11-19 18:37:11 +08:00
|
|
|
PENDING_RESULT_HIT,
|
2018-10-25 18:45:33 +08:00
|
|
|
PENDING_RESULT_MISS
|
|
|
|
|
};
|
2018-12-22 19:52:49 +06:00
|
|
|
const char* cache_pending_result_string(enum cache_pending_result);
|
2018-11-07 21:05:21 +08:00
|
|
|
struct cache_mid;
|
2018-11-13 11:56:41 +08:00
|
|
|
void cache_mid_clear(struct cache_mid **mid);
|
2018-11-07 21:05:21 +08:00
|
|
|
|
2019-01-07 19:42:23 +06:00
|
|
|
const struct cached_meta* cache_pending_result_read_meta(future_result_t * result, struct cache_mid* mid);
|
2018-10-25 18:45:33 +08:00
|
|
|
enum cache_pending_result web_cache_async_pending(struct cache_handle* handle, unsigned int thread_id,
|
2018-11-07 21:05:21 +08:00
|
|
|
const struct tfe_http_half * request, struct cache_mid **mid, struct future* f_revalidate);
|
2018-11-13 11:56:41 +08:00
|
|
|
|
2018-10-25 18:45:33 +08:00
|
|
|
|
2018-10-14 17:11:45 +08:00
|
|
|
|
|
|
|
|
|
2018-12-21 13:16:36 +06:00
|
|
|
struct cache_write_context;
|
2023-03-30 19:39:18 +08:00
|
|
|
struct cache_write_context* web_cache_write_start(struct cache_handle* handle, unsigned int thread_id,
|
2018-11-07 21:05:21 +08:00
|
|
|
const struct tfe_http_session * session, struct cache_mid **mid);
|
2018-12-21 13:16:36 +06:00
|
|
|
void web_cache_write(struct cache_write_context* ctx, const unsigned char * body_frag, size_t frag_size);
|
2018-12-22 19:52:49 +06:00
|
|
|
//return 1 on success
|
|
|
|
|
//return -1 on failed
|
|
|
|
|
//return -2 on cancel
|
|
|
|
|
|
|
|
|
|
int web_cache_write_end(struct cache_write_context* ctx);
|
2018-10-14 17:11:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|