Configuring MaxScale's Cache Filter

MaxScale's Cache Filter (cache) caches the result-sets of SELECT statements to improve query performance.

This page explains how to configure the filter.

Configuring the Cache Filter

  1. Configure the Cache Filter by attaching it to a router service in maxscale.cnf.

    You may also need to set specific parameters for the filter to get the maximum benefit for your workload.

    Parameter

    Description

    hard_ttl

    • This parameter defines the hard time to live.

    • This is the maximum amount of time that a cached result is used before it is discarded and refreshed.

    • The value can be followed by any of the following units: h, m, s, and ms, for specifying durations in hours, minutes, seconds, and milliseconds.

    • The default value is 0 seconds, which means that there is no limit.

    soft_ttl

    • This parameter defines the soft time to live.

    • This is the maximum amount of time that a cached result is used before it is discarded and refreshed.

    • However, as long as hard_ttl has not passed, all other clients requesting the same value will use the result from the cache while it is being fetched from the backend. That is, as long as soft_ttl but not hard_ttl has passed, even if several clients request the same value at the same time, there will be just one request to the backend.

    • The value can be followed by any of the following units: h, m, s, and ms, for specifying durations in hours, minutes, seconds, and milliseconds.

    • If the value of soft_ttl is larger than hard_ttl it will be adjusted down to the same value.

    • The default value is 0 seconds, which means that there is no limit.

    For example:

    [split-router-cache]
    type                    = filter
    module                  = cache
    hard_ttl                = 30s
    soft_ttl                = 20s
    
    [cached-split-router]
    type                     = service
    router                   = readwritesplit
    ...
    filters                  = split-router-cache
    
  2. Restart the MaxScale instance.

    On operating systems that use systemd:

    $ sudo systemctl restart maxscale
    

    On systems that use Upstart:

    $ sudo service maxscale restart