class cliquet.cache.postgresql.Cache(client, *args, **kwargs)

Cache backend using PostgreSQL.

Enable in configuration:

cliquet.cache_backend = cliquet.cache.postgresql

Database location URI can be customized:

cliquet.cache_url = postgres://user:pass@db.server.lan:5432/dbname

Alternatively, username and password could also rely on system user ident or even specified in ~/.pgpass (see PostgreSQL documentation).


Some tables and indices are created when cliquet migrate is run. This requires some privileges on the database, or some error will be raised.

Alternatively, the schema can be initialized outside the python application, using the SQL file located in cliquet/cache/postgresql/schema.sql. This allows to distinguish schema manipulation privileges from schema usage.

A connection pool is enabled by default:

cliquet.cache_pool_size = 10
cliquet.cache_maxoverflow = 10
cliquet.cache_max_backlog = -1
cliquet.cache_pool_recycle = -1
cliquet.cache_pool_timeout = 30
cliquet.cache_poolclass =

The max_backlog limits the number of threads that can be in the queue waiting for a connection. Once this limit has been reached, any further attempts to acquire a connection will be rejected immediately, instead of locking up all threads by keeping them waiting in the queue.

See dedicated section in SQLAlchemy documentation for default values and behaviour.


Using a dedicated connection pool is still recommended to allow load balancing, replication or limit the number of connections used in a multi-process deployment.



class cliquet.cache.redis.Cache(client, *args, **kwargs)

Cache backend implementation using Redis.

Enable in configuration:

cliquet.cache_backend = cliquet.cache.redis

(Optional) Instance location URI can be customized:

cliquet.cache_url = redis://localhost:6379/1

A threaded connection pool is enabled by default:

cliquet.cache_pool_size = 50

If the database is used for multiple Kinto deployement cache, you may want to add a prefix to every key to avoid collision:

cliquet.cache_prefix = stack1_


class cliquet.cache.memory.Cache(*args, **kwargs)

Cache backend implementation in local thread memory.

Enable in configuration:

cliquet.cache_backend = cliquet.cache.memory


Implementing a custom cache backend consists on implementing the following interface:

class cliquet.cache.CacheBase(*args, **kwargs)

Create every necessary objects (like tables or indices) in the backend.

This is excuted when the cliquet migrate command is ran.


Delete every values.


Obtain the expiration value of the specified key.

Parameters:key (str) – key
Returns:number of seconds or negative if no TTL.
Return type:float
expire(key, ttl)

Set the expiration value ttl for the specified key.

  • key (str) – key
  • ttl (float) – number of seconds
set(key, value, ttl=None)

Store a value with the specified key. If ttl is provided, set an expiration value.

  • key (str) – key
  • value (str) – value to store
  • ttl (float) – expire after number of seconds

Obtain the value of the specified key.

Parameters:key (str) – key
Returns:the stored value or None if missing.
Return type:str

Delete the value of the specified key.

Parameters:key (str) – key