The zaqar.openstack.common.cache.backends module

class BaseCache(parsed_url, options=None)

Bases: object

Base Cache Abstraction

Params parsed_url:
 

Parsed url object.

Params options:

A dictionary with configuration parameters for the cache. For example:

  • default_ttl: An integer defining the default ttl for keys.
append(key, value)

Appends value to key‘s value.

Params key:The key of the value to which tail should be appended.
Params value:The value to append to the original.
Returns:The new value
append_tail(key, tail)

Appends tail to key‘s value.

Params key:The key of the value to which tail should be appended.
Params tail:The list of values to append to the original.
Returns:The new value
clear()

Removes all items from the cache.

Note

Thread-safety is required and it has to be guaranteed by the backend implementation.

get(key, default=None)

Gets one item from the cache

Note

Thread-safety is required and it has to be guaranteed by the backend implementation.

Params key:Key for the item to retrieve from the cache.
Params default:The default value to return.
Returns:key‘s value in the cache if it exists, otherwise default should be returned.
get_many(keys, default=<object object at 0x7f0e07f0a570>)

Gets keys’ value from cache

Params keys:List of keys to retrieve.
Params default:The default value to return for each key that is not in the cache.
Returns:A generator of (key, value)
incr(key, delta=1)

Increments the value for a key

Params key:The key for the value to be incremented
Params delta:Number of units by which to increment the value. Pass a negative number to decrement the value.
Returns:The new value
set(key, value, ttl, not_exists=False)

Sets or updates a cache entry

Note

Thread-safety is required and has to be guaranteed by the backend implementation.

Params key:Item key as string.
Params value:Value to assign to the key. This can be anything that is handled by the current backend.
Params ttl:Key’s timeout in seconds. 0 means no timeout.
Params not_exists:
 If True, the key will be set if it doesn’t exist. Otherwise, it’ll always be set.
Returns:True if the operation succeeds, False otherwise.
set_many(data, ttl=None)

Puts several items into the cache at once

Depending on the backend, this operation may or may not be efficient. The default implementation calls set for each (key, value) pair passed, other backends support set_many operations as part of their protocols.

Params data:A dictionary like {key: val} to store in the cache.
Params ttl:Key’s timeout in seconds.
setdefault(key, value)

Sets the key value to value if it doesn’t exist

Params key:Item key as string.
Params value:Value to assign to the key. This can be anything that is handled by the current backend.
unset_many(keys)

Removes several keys from the cache at once

Params keys:List of keys to unset.
update(**kwargs)

Sets several (key, value) paris.

Refer to the set_many docstring.

Previous topic

The zaqar.openstack.common.cache._backends.memory module

Next topic

The zaqar.openstack.common.cache.cache module

Project Source

This Page