Navigation Menu

Skip to content

Commit

Permalink
Add grn_cache_default_reopen()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 26, 2017
1 parent 85ea3bd commit ba3aee6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/groonga/cache.h
Expand Up @@ -36,6 +36,8 @@ GRN_API grn_rc grn_cache_close(grn_ctx *ctx, grn_cache *cache);
GRN_API grn_rc grn_cache_current_set(grn_ctx *ctx, grn_cache *cache);
GRN_API grn_cache *grn_cache_current_get(grn_ctx *ctx);

GRN_API grn_rc grn_cache_default_reopen(void);

GRN_API grn_rc grn_cache_set_max_n_entries(grn_ctx *ctx,
grn_cache *cache,
unsigned int n);
Expand Down
27 changes: 27 additions & 0 deletions lib/cache.c
Expand Up @@ -425,6 +425,33 @@ grn_cache_init(void)
grn_cache_current_set(ctx, grn_cache_default);
}

grn_rc
grn_cache_default_reopen(void)
{
grn_ctx *ctx = &grn_cache_ctx;
grn_cache *new_default;
grn_bool default_is_current;

GRN_API_ENTER;

new_default = grn_cache_open(ctx);
if (!new_default) {
GRN_API_RETURN(ctx->rc);
}

default_is_current = (grn_cache_default == grn_cache_current_get(ctx));
if (default_is_current) {
grn_cache_current_set(ctx, new_default);
}

if (grn_cache_default) {
grn_cache_close(ctx, grn_cache_default);
}
grn_cache_default = new_default;

GRN_API_RETURN(ctx->rc);
}

static void
grn_cache_expire_entry_memory(grn_cache *cache, grn_cache_entry_memory *ce)
{
Expand Down

0 comments on commit ba3aee6

Please sign in to comment.