Groonga
Loading...
Searching...
No Matches
cache.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GRN_CACHE_DEFAULT_MAX_N_ENTRIES   100
 

Typedefs

typedef struct _grn_cache grn_cache
 Cache object.
 

Functions

GRN_API void grn_set_default_cache_base_path (const char *base_path)
 
GRN_API const char * grn_get_default_cache_base_path (void)
 
GRN_API grn_cachegrn_cache_open (grn_ctx *ctx)
 Create a new cache object.
 
GRN_API grn_cachegrn_persistent_cache_open (grn_ctx *ctx, const char *base_path)
 
GRN_API grn_rc grn_cache_close (grn_ctx *ctx, grn_cache *cache)
 Free resourses of the cache.
 
GRN_API grn_rc grn_cache_current_set (grn_ctx *ctx, grn_cache *cache)
 Set the current grn_cache object.
 
GRN_API grn_cachegrn_cache_current_get (grn_ctx *ctx)
 Retrieve the current grn_cache object.
 
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)
 Set the maximum number of entries in the grn_cache object.
 
GRN_API unsigned int grn_cache_get_max_n_entries (grn_ctx *ctx, grn_cache *cache)
 Retrieve the maximum number of entries in the grn_cache object.
 

Macro Definition Documentation

◆ GRN_CACHE_DEFAULT_MAX_N_ENTRIES

#define GRN_CACHE_DEFAULT_MAX_N_ENTRIES   100

Typedef Documentation

◆ grn_cache

typedef struct _grn_cache grn_cache

Cache object.

You can create a new cache object using grn_cache_open, and free it using grn_cache_close.

Function Documentation

◆ grn_cache_close()

GRN_API grn_rc grn_cache_close ( grn_ctx ctx,
grn_cache cache 
)

Free resourses of the cache.

Parameters
ctxThe context object.
cacheThe cache object to be freed.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.

◆ grn_cache_current_get()

GRN_API grn_cache * grn_cache_current_get ( grn_ctx ctx)

Retrieve the current grn_cache object.

Parameters
ctxThe context object.
Returns
The grn_cache object is associated with the database that the context is using. If there is no specific cache, it returns the current cache which might be NULL.

◆ grn_cache_current_set()

GRN_API grn_rc grn_cache_current_set ( grn_ctx ctx,
grn_cache cache 
)

Set the current grn_cache object.

Parameters
ctxThe context object.
cacheThe new current cache object.
Returns
GRN_SUCCESS always.

◆ grn_cache_default_reopen()

GRN_API grn_rc grn_cache_default_reopen ( void  )

◆ grn_cache_get_max_n_entries()

GRN_API unsigned int grn_cache_get_max_n_entries ( grn_ctx ctx,
grn_cache cache 
)

Retrieve the maximum number of entries in the grn_cache object.

Parameters
ctxThe context object.
cacheThe cache object whose maximum entry count is to be retrieved.
Returns
The maximum number of entries for grn_cache object.

◆ grn_cache_open()

GRN_API grn_cache * grn_cache_open ( grn_ctx ctx)

Create a new cache object.

It initializes a cache based on the current configuration or environment settings. The cache operates in either memory mode or persistent mode.

Cache Modes

Memory Cache:

  • The same cache is shared within the same process.
  • The same cache isn't shared across multiple processes.

Persistent Cache:

  • The same cache is shared across multiple processes.
  • Persistent cache is slightly slower than memory cache due to filesystem I/O.

Cache Mode Configuration

Cache mode can be configured in three ways:

Server/Daemon Option

When starting Groonga, use the --cache-base-path option to specify the cache base path. Setting this option to a valid path enables persistent cache mode.

Environment Variable

If the --cache-base-path option is not set when you start Groonga, the function checks the GRN_CACHE_TYPE environment variable.

  • If GRN_CACHE_TYPE is set to persistent, it enables persistent cache mode without a specified base path.
  • If GRN_CACHE_TYPE is set to any other value or is unset, it uses memory cache mode.

C API

Use grn_set_default_cache_base_path to override the configuration or environment settings at runtime.

Parameters
ctxThe context object used for memory allocation and error handling.
Returns
A newly created grn_cache object on success, NULL on error. The returned grn_cache object must be freed by grn_cache_close. See ctx->rc for error details.

◆ grn_cache_set_max_n_entries()

GRN_API grn_rc grn_cache_set_max_n_entries ( grn_ctx ctx,
grn_cache cache,
unsigned int  n 
)

Set the maximum number of entries in the grn_cache object.

Parameters
ctxThe context object.
cacheThe cache object whose maximum entry count is updated.
nThe new maximum number of entries.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.

◆ grn_get_default_cache_base_path()

GRN_API const char * grn_get_default_cache_base_path ( void  )

◆ grn_persistent_cache_open()

GRN_API grn_cache * grn_persistent_cache_open ( grn_ctx ctx,
const char *  base_path 
)

◆ grn_set_default_cache_base_path()

GRN_API void grn_set_default_cache_base_path ( const char *  base_path)