统一cache的动作名称:write、read、pend。
This commit is contained in:
@@ -500,7 +500,7 @@ static void pangu_http_ctx_free(struct pangu_http_ctx * ctx)
|
||||
}
|
||||
if(ctx->cache_update_ctx)
|
||||
{
|
||||
web_cache_update_end(ctx->cache_update_ctx);
|
||||
web_cache_write_end(ctx->cache_update_ctx);
|
||||
ctx->cache_update_ctx=NULL;
|
||||
}
|
||||
|
||||
@@ -1067,7 +1067,7 @@ int dummy_resume(const struct tfe_stream * stream, const struct tfe_http_session
|
||||
return RESUMED_CB_NO_MORE_CALLS;
|
||||
}
|
||||
|
||||
static void cache_query_on_succ(future_result_t * result, void * user)
|
||||
static void cache_read_on_succ(future_result_t * result, void * user)
|
||||
{
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
const struct cached_meta* meta=NULL;
|
||||
@@ -1124,7 +1124,7 @@ static void cache_query_on_succ(future_result_t * result, void * user)
|
||||
}
|
||||
return;
|
||||
}
|
||||
static void cache_query_on_fail(enum e_future_error err, const char * what, void * user)
|
||||
static void cache_read_on_fail(enum e_future_error err, const char * what, void * user)
|
||||
{
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
future_destroy(ctx->f_cache_query);
|
||||
@@ -1142,7 +1142,7 @@ static void cache_query_on_fail(enum e_future_error err, const char * what, void
|
||||
ctx->pending_result=PENDING_RESULT_MISS;
|
||||
printf("cache query failed: %s %s\n", ctx->ref_session->req->req_spec.url, what);
|
||||
}
|
||||
static void cache_pending_on_succ(future_result_t * result, void * user)
|
||||
static void cache_pend_on_succ(future_result_t * result, void * user)
|
||||
{
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
const struct cached_meta* meta=NULL;
|
||||
@@ -1188,7 +1188,7 @@ static void cache_pending_on_succ(future_result_t * result, void * user)
|
||||
ctx->resumed_cb=make_revalidate_request;
|
||||
return;
|
||||
}
|
||||
static void cache_pending_on_fail(enum e_future_error err, const char * what, void * user)
|
||||
static void cache_pend_on_fail(enum e_future_error err, const char * what, void * user)
|
||||
{
|
||||
struct pangu_http_ctx * ctx = (struct pangu_http_ctx *)user;
|
||||
|
||||
@@ -1201,9 +1201,9 @@ static void cache_pending_on_fail(enum e_future_error err, const char * what, vo
|
||||
return;
|
||||
}
|
||||
|
||||
void cache_pending(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
void cache_pend(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
{
|
||||
ctx->f_cache_pending=future_create("cache_pend", cache_pending_on_succ, cache_pending_on_fail, ctx);
|
||||
ctx->f_cache_pending=future_create("cache_pend", cache_pend_on_succ, cache_pend_on_fail, ctx);
|
||||
ctx->ref_session=tfe_http_session_allow_write(session);
|
||||
ctx->pending_result=web_cache_async_pending(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_pending);
|
||||
switch(ctx->pending_result)
|
||||
@@ -1222,10 +1222,10 @@ void cache_pending(const struct tfe_http_session * session, unsigned int thread_
|
||||
}
|
||||
return;
|
||||
}
|
||||
void cache_query(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
void cache_read(const struct tfe_http_session * session, unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
{
|
||||
ctx->f_cache_query=future_create("cache_get", cache_query_on_succ, cache_query_on_fail, ctx);
|
||||
int ret=web_cache_async_query(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_query);
|
||||
ctx->f_cache_query=future_create("cache_get", cache_read_on_succ, cache_read_on_fail, ctx);
|
||||
int ret=web_cache_async_read(g_pangu_rt->cache, thread_id, session->req, &(ctx->cmid), ctx->f_cache_query);
|
||||
if(ret==0)
|
||||
{
|
||||
ctx->ref_session=tfe_http_session_allow_write(session);
|
||||
@@ -1238,22 +1238,22 @@ void cache_query(const struct tfe_http_session * session, unsigned int thread_id
|
||||
}
|
||||
}
|
||||
|
||||
void cache_update(const struct tfe_http_session * session, enum tfe_http_event events,
|
||||
void cache_write(const struct tfe_http_session * session, enum tfe_http_event events,
|
||||
const unsigned char * body_frag, size_t frag_size,
|
||||
unsigned int thread_id, struct pangu_http_ctx * ctx)
|
||||
{
|
||||
|
||||
if(events & EV_HTTP_RESP_BODY_BEGIN)
|
||||
{
|
||||
ctx->cache_update_ctx=web_cache_update_start(g_pangu_rt->cache, thread_id, session, &(ctx->cmid));
|
||||
ctx->cache_update_ctx=web_cache_write_start(g_pangu_rt->cache, thread_id, session, &(ctx->cmid));
|
||||
}
|
||||
if(events & EV_HTTP_RESP_BODY_CONT && ctx->cache_update_ctx!=NULL)
|
||||
{
|
||||
web_cache_update(ctx->cache_update_ctx, body_frag, frag_size);
|
||||
web_cache_write(ctx->cache_update_ctx, body_frag, frag_size);
|
||||
}
|
||||
if(events & EV_HTTP_RESP_BODY_END && ctx->cache_update_ctx!=NULL)
|
||||
{
|
||||
web_cache_update_end(ctx->cache_update_ctx);
|
||||
web_cache_write_end(ctx->cache_update_ctx);
|
||||
ctx->cache_update_ctx=NULL;
|
||||
//printf("cache update success: %s\n", ctx->ref_session->req->req_spec.url);
|
||||
}
|
||||
@@ -1350,23 +1350,23 @@ void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_
|
||||
{
|
||||
if(events & EV_HTTP_REQ_HDR)
|
||||
{
|
||||
cache_pending(session, thread_id, ctx);
|
||||
cache_pend(session, thread_id, ctx);
|
||||
if(ctx->pending_result==PENDING_RESULT_ALLOWED)
|
||||
{
|
||||
cache_query(session, thread_id, ctx);
|
||||
cache_read(session, thread_id, ctx);
|
||||
}
|
||||
}
|
||||
if(events & EV_HTTP_RESP_HDR && ctx->pending_result==PENDING_RESULT_REVALIDATE)
|
||||
{
|
||||
if(session->resp->resp_spec.resp_code==TFE_HTTP_STATUS_NOT_MODIFIED)
|
||||
{
|
||||
cache_query(session, thread_id, ctx);
|
||||
cache_read(session, thread_id, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
if(tfe_http_in_response(events) && ctx->pending_result==PENDING_RESULT_MISS)
|
||||
{
|
||||
cache_update(session, events, body_frag, frag_size, thread_id, ctx);
|
||||
cache_write(session, events, body_frag, frag_size, thread_id, ctx);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user