Skip to content

Commit

Permalink
Updated cache module and its dependencies
Browse files Browse the repository at this point in the history
This is to avoid cache module dependency on timeutils that are now moved
to oslo.utils.

The following changes are included:

 * neutron/openstack/common/cache/_backends/memory.py
  6ff6b4b Switch oslo-incubator to use oslo.utils and remove old modules
  2bedce3 Fix MemoryBackend not purging item from _keys_expired on delete

 * neutron/openstack/common/cache/backends.py
  39625e1 Set pbr 'warnerrors' option for doc build

 * neutron/openstack/common/cache/cache.py
  9c683be fix small typo

 * neutron/openstack/common/lockutils.py
  5d40e14 Remove code that moved to oslo.i18n
  7209975 Always log the releasing, even under failure
  bbb266c Clarify logging in lockutils
  942e1aa Use file locks by default again
  ac995be Fix E126 pep8 errors
  15b8352 Remove oslo.log from lockutils

Change-Id: I02cb4b2bc4b7bcba948e67cffdb8bd0219c89a29
  • Loading branch information
booxter committed Oct 17, 2014
1 parent 623a30b commit d739790
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 125 deletions.
5 changes: 3 additions & 2 deletions neutron/openstack/common/cache/_backends/memory.py
Expand Up @@ -14,9 +14,10 @@

import collections

from oslo.utils import timeutils

from neutron.openstack.common.cache import backends
from neutron.openstack.common import lockutils
from neutron.openstack.common import timeutils


class MemoryBackend(backends.BaseCache):
Expand Down Expand Up @@ -147,7 +148,7 @@ def __delitem__(self, key):
try:
# NOTE(flaper87): Keys with ttl == 0
# don't exist in the _keys_expires dict
self._keys_expires[value[0]].remove(value[1])
self._keys_expires[value[0]].remove(key)
except (KeyError, ValueError):
pass

Expand Down
83 changes: 35 additions & 48 deletions neutron/openstack/common/cache/backends.py
Expand Up @@ -26,9 +26,9 @@ class BaseCache(object):
: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.
for the cache. For example:
- default_ttl: An integer defining the default ttl for keys.
"""

def __init__(self, parsed_url, options=None):
Expand All @@ -43,20 +43,17 @@ def _set(self, key, value, ttl, not_exists=False):
def set(self, 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.
.. note:: Thread-safety is required and has to be guaranteed by the
backend implementation.
:params key: Item key as string.
:type key: `unicode 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 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.
:type ttl: int
:params not_exists: If True, the key will be set
if it doesn't exist. Otherwise,
it'll always be set.
:params not_exists: If True, the key will be set if it doesn't exist.
Otherwise, it'll always be set.
:type not_exists: bool
:returns: True if the operation succeeds, False otherwise.
Expand All @@ -74,9 +71,8 @@ def setdefault(self, key, value):
:params key: Item key as string.
:type key: `unicode string`
:params value: Value to assign to the key. This
can be anything that is handled
by the current backend.
:params value: Value to assign to the key. This can be anything that
is handled by the current backend.
"""
try:
return self[key]
Expand All @@ -91,15 +87,14 @@ def _get(self, key, default):
def get(self, key, default=None):
"""Gets one item from the cache
NOTE: Thread-safety is required and it has to be
guaranteed by the backend implementation.
.. 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 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.
:returns: `key`'s value in the cache if it exists, otherwise
`default` should be returned.
"""
return self._get(key, default)

Expand All @@ -115,8 +110,8 @@ def __getitem__(self, key):
def __delitem__(self, key):
"""Removes an item from cache.
NOTE: Thread-safety is required and it has to be
guaranteed by the backend implementation.
.. note:: Thread-safety is required and it has to be guaranteed by
the backend implementation.
:params key: The key to remove.
Expand All @@ -130,8 +125,8 @@ def _clear(self):
def clear(self):
"""Removes all items from the cache.
NOTE: Thread-safety is required and it has to be
guaranteed by the backend implementation.
.. note:: Thread-safety is required and it has to be guaranteed by
the backend implementation.
"""
return self._clear()

Expand All @@ -143,9 +138,8 @@ def incr(self, 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.
:params delta: Number of units by which to increment the value.
Pass a negative number to decrement the value.
:returns: The new value
"""
Expand All @@ -158,10 +152,8 @@ def _append_tail(self, key, tail):
def append_tail(self, 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.
: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
"""
Expand All @@ -181,10 +173,8 @@ def append_tail(self, key, tail):
def append(self, 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.
: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
"""
Expand All @@ -196,8 +186,7 @@ def __contains__(self, key):
:params key: The key to verify.
:returns: True if the key exists,
otherwise False.
:returns: True if the key exists, otherwise False.
"""

@abc.abstractmethod
Expand All @@ -209,9 +198,8 @@ def get_many(self, keys, default=NOTSET):
"""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.
:params default: The default value to return for each key that is not
in the cache.
:returns: A generator of (key, value)
"""
Expand All @@ -227,13 +215,12 @@ def _set_many(self, data, ttl):
def set_many(self, 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.
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 data: A dictionary like {key: val} to store in the cache.
:params ttl: Key's timeout in seconds.
"""

Expand Down
4 changes: 2 additions & 2 deletions neutron/openstack/common/cache/cache.py
Expand Up @@ -24,7 +24,7 @@
from stevedore import driver


def _get_olso_configs():
def _get_oslo_configs():
"""Returns the oslo.config options to register."""
# NOTE(flaper87): Oslo config should be
# optional. Instead of doing try / except
Expand All @@ -45,7 +45,7 @@ def register_oslo_configs(conf):
:params conf: Config object.
:type conf: `cfg.ConfigOptions`
"""
conf.register_opts(_get_olso_configs())
conf.register_opts(_get_oslo_configs())


def get_cache(url='memory://'):
Expand Down

0 comments on commit d739790

Please sign in to comment.