#pragma once
#include <event2/event.h>
#include <event2/buffer.h>
#include <tfe_future.h>

enum cache_query_status
{
	WEB_CACHE_BEFORE_QUERY=0,
	WEB_CACHE_NOT_APPLICABLE,
	WEB_CACHE_QUERING,
	WEB_CACHE_NOT_HIT,
	WEB_CACHE_HIT
};
struct cache_handle;
struct cache_handle* create_web_cache_handle(const char* profile_path, const char* section, struct event_base* gc_evbase, void *logger);
struct cached_meta
{
	size_t content_length;
	char* content_type;
};
struct cached_meta* cache_query_result_get_header(future_result_t * result);
void cache_query_free_meta(struct cached_meta* meta);
size_t cache_query_result_get_data(future_result_t * result, const unsigned char** pp_data);

enum cache_query_status async_web_cache_query(struct cache_handle* handle, unsigned int thread_id,
										const struct tfe_http_half * request, struct future* f);
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);



struct cache_update_context;
struct cache_update_context* web_cache_update_start(struct cache_handle* handle, unsigned int thread_id, 
															const struct tfe_http_session * session);
void web_cache_update(struct cache_update_context* ctx, const unsigned char * body_frag, size_t frag_size);
void web_cache_update_end(struct cache_update_context* ctx);



