Files
MaxScale/Documentation/Filters/Cache.md
2016-09-22 14:22:45 +03:00

3.1 KiB

#Cache

Overview

The cache filter is capable of caching the result of SELECTs, so that subsequent identical SELECTs are served directly by MaxScale, without being routed to any server.

Configuration

The cache filter is straightforward to configure and simple to add to any existing service.

[Cache]
type=filter
module=cache
ttl=5
storage=...
storage_options=...

[Cached Routing Service]
type=service
...
filters=Cache

Each configured cache filter uses a storage of its own. That is, if there are two services, each configured with a specific cache filter, then, even if queries target the very same servers the cached data will not be shared.

Two services can use the same cache filter, but then either the services should use the very same servers or a completely different set of servers, where the used table names are different. Otherwise there can be unintended sharing.

Filter Parameters

The cache filter has one mandatory parameter - storage - and a few optional ones.

storage

The name of the module that provides the storage for the cache. That module will be loaded and provided with the value of storage_options as argument. For instance:

storage=storage_rocksdb

storage_options

A comma separated list of arguments to be provided to the storage module, specified in storage, when it is loaded. Note that the needed arguments depend upon the specific module. For instance,

storage_options=storage_specific_option1=value1,storage_specific_option2=value2

allowed_references

Specifies whether any or only fully qualified references are allowed in queries stored to the cache.

allowed_references=[qualified|any]

The default is qualified, which means that only queries where the database name is included in the table name are subject to caching.

select col from db.tbl;

If any is specified, then also queries where the table name is not fully qualified are subject to caching.

select col from tbl;

Care should be excersized before this setting is changed, because, for instance, the following is likely to produce unexpected results.

use db1;
select col from tbl;
...
use db2;
select col from tbl;

The setting can be changed to any, provided fully qualified names are always used or if the names of tables in different databases are different.

max_resultset_rows

Specifies the maximum number of rows a resultset can have in order to be stored in the cache. A resultset larger than this, will not be stored.

max_resultset_rows=1000

Zero or a negative value is interpreted as no limitation.

The default value is -1.

max_resultset_size

Specifies the maximum size a resultset can have, measured in kibibytes, in order to be stored in the cache. A resultset larger than this, will not be stored.

max_resultset_size=128

The default value is 64.

ttl

Time to live; the amount of time - in seconds - the cached result is used before it is refreshed from the server.

If nothing is specified, the default ttl value is 10.

ttl=60

#Storage

Storage RocksDB