# Path: cio/backends/base.py
# class CacheBackend(BaseBackend):
# 
#     NONE = '__None__'
# 
#     def get(self, uri):
#         """
#         Return node for uri or None if not exists:
#             {uri: x, content: y}
#         """
#         cache_key = self._build_cache_key(uri)
#         value = self._get(cache_key)
#         if value is not None:
#             return self._decode_node(uri, value)
# 
#     def get_many(self, uris):
#         """
#         Return request uri map of found nodes as dicts:
#             {requested_uri: {uri: x, content: y}}
#         """
#         cache_keys = dict((self._build_cache_key(uri), uri) for uri in uris)
#         result = self._get_many(cache_keys)
#         nodes = {}
#         for cache_key in result:
#             uri = cache_keys[cache_key]
#             value = result[cache_key]
#             node = self._decode_node(uri, value)
#             if node:
#                 nodes[uri] = node
#         return nodes
# 
#     def set(self, uri, content):
#         """
#         Cache node content for uri.
#         No return.
#         """
#         key, value = self._prepare_node(uri, content)
#         self._set(key, value)
# 
#     def set_many(self, nodes):
#         """
#         Takes nodes dict {uri: content, ...} as argument.
#         No return.
#         """
#         data = self._prepare_nodes(nodes)
#         self._set_many(data)
# 
#     def delete(self, uri):
#         """
#         Remove node uri from cache.
#         No return.
#         """
#         cache_key = self._build_cache_key(uri)
#         self._delete(cache_key)
# 
#     def delete_many(self, uris):
#         """
#         Remove many nodes from cache.
#         No return.
#         """
#         cache_keys = (self._build_cache_key(uri) for uri in uris)
#         self._delete_many(cache_keys)
# 
#     def clear(self):
#         """
#         Removes all nodes from cache
#         """
#         raise NotImplementedError  # pragma: no cover
# 
#     def _build_cache_key(self, uri):
#         """
#         Build sha1 hex cache key to handle key length and whitespace to be compatible with Memcached
#         """
#         key = uri.clone(ext=None, version=None)
# 
#         if six.PY3:
#             key = key.encode('utf-8')
# 
#         return sha1(key).hexdigest()
# 
#     def _get(self, key):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _get_many(self, keys):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _set(self, key, value):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _set_many(self, data):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _delete(self, key):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _delete_many(self, keys):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _encode_content(self, uri, content):
#         """
#         Encode/pack node uri and content in a way that the cache backend are able to persist.
#         """
#         return uri, content
# 
#     def _decode_content(self, content):
#         """
#         Decode/unpack cached node to uri and unicode content.
#         """
#         uri, content = content
#         return uri, content
# 
#     def _decode_node(self, uri, content):
#         _uri, _content = self._decode_content(content)
#         if _uri:
#             _uri = URI(_uri)
#             if uri.ext in (None, _uri.ext):  # Validate plugin
#                 return {
#                     'uri': _uri,
#                     'content': _content
#                 }
# 
#     def _prepare_node(self, uri, content):
#         key = self._build_cache_key(uri)
#         value = self._encode_content(uri, content)
#         return key, value
# 
#     def _prepare_nodes(self, nodes):
#         return dict(self._prepare_node(uri, content) for uri, content in six.iteritems(nodes))


import six
from ..base import CacheBackend

    scheme = 'locmem'

    def __init__(self, **config):
        super(LocMemCacheBackend, self).__init__(**config)
        self._cache = {}
        self.calls = 0
        self.hits = 0
        self.misses = 0
        self.sets = 0

    def clear(self):
        self._cache.clear()

    def _get(self, key):
        value = self._cache.get(key)
        self.calls += 1
        if value is None:
            self.misses += 1
        else:
            self.hits += 1
        return value

    def _get_many(self, keys):
        result = {}
        for key in keys:
            value = self._cache.get(key)
            if value is not None:
                result[key] = value
                self.hits += 1

# Path: cio/backends/base.py
# class CacheBackend(BaseBackend):
# 
#     NONE = '__None__'
# 
#     def get(self, uri):
#         """
#         Return node for uri or None if not exists:
#             {uri: x, content: y}
#         """
#         cache_key = self._build_cache_key(uri)
#         value = self._get(cache_key)
#         if value is not None:
#             return self._decode_node(uri, value)
# 
#     def get_many(self, uris):
#         """
#         Return request uri map of found nodes as dicts:
#             {requested_uri: {uri: x, content: y}}
#         """
#         cache_keys = dict((self._build_cache_key(uri), uri) for uri in uris)
#         result = self._get_many(cache_keys)
#         nodes = {}
#         for cache_key in result:
#             uri = cache_keys[cache_key]
#             value = result[cache_key]
#             node = self._decode_node(uri, value)
#             if node:
#                 nodes[uri] = node
#         return nodes
# 
#     def set(self, uri, content):
#         """
#         Cache node content for uri.
#         No return.
#         """
#         key, value = self._prepare_node(uri, content)
#         self._set(key, value)
# 
#     def set_many(self, nodes):
#         """
#         Takes nodes dict {uri: content, ...} as argument.
#         No return.
#         """
#         data = self._prepare_nodes(nodes)
#         self._set_many(data)
# 
#     def delete(self, uri):
#         """
#         Remove node uri from cache.
#         No return.
#         """
#         cache_key = self._build_cache_key(uri)
#         self._delete(cache_key)
# 
#     def delete_many(self, uris):
#         """
#         Remove many nodes from cache.
#         No return.
#         """
#         cache_keys = (self._build_cache_key(uri) for uri in uris)
#         self._delete_many(cache_keys)
# 
#     def clear(self):
#         """
#         Removes all nodes from cache
#         """
#         raise NotImplementedError  # pragma: no cover
# 
#     def _build_cache_key(self, uri):
#         """
#         Build sha1 hex cache key to handle key length and whitespace to be compatible with Memcached
#         """
#         key = uri.clone(ext=None, version=None)
# 
#         if six.PY3:
#             key = key.encode('utf-8')
# 
#         return sha1(key).hexdigest()
# 
#     def _get(self, key):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _get_many(self, keys):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _set(self, key, value):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _set_many(self, data):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _delete(self, key):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _delete_many(self, keys):
#         raise NotImplementedError  # pragma: no cover
# 
#     def _encode_content(self, uri, content):
#         """
#         Encode/pack node uri and content in a way that the cache backend are able to persist.
#         """
#         return uri, content
# 
#     def _decode_content(self, content):
#         """
#         Decode/unpack cached node to uri and unicode content.
#         """
#         uri, content = content
#         return uri, content
# 
#     def _decode_node(self, uri, content):
#         _uri, _content = self._decode_content(content)
#         if _uri:
#             _uri = URI(_uri)
#             if uri.ext in (None, _uri.ext):  # Validate plugin
#                 return {
#                     'uri': _uri,
#                     'content': _content
#                 }
# 
#     def _prepare_node(self, uri, content):
#         key = self._build_cache_key(uri)
#         value = self._encode_content(uri, content)
#         return key, value
# 
#     def _prepare_nodes(self, nodes):
#         return dict(self._prepare_node(uri, content) for uri, content in six.iteritems(nodes))


# Path: cio/backends/locmem/backend.py
import six
from ..base import CacheBackend


    scheme = 'locmem'

    def __init__(self, **config):
        super(LocMemCacheBackend, self).__init__(**config)
        self._cache = {}
        self.calls = 0
        self.hits = 0
        self.misses = 0
        self.sets = 0

    def clear(self):
        self._cache.clear()

    def _get(self, key):
        value = self._cache.get(key)
        self.calls += 1
        if value is None:
            self.misses += 1
        else:
            self.hits += 1
        return value

    def _get_many(self, keys):
        result = {}
        for key in keys:
            value = self._cache.get(key)
            if value is not None:
                result[key] = value
                self.hits += 1

            else: