Skip to content

Commit

Permalink
Remove DefaultMapping abstract base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Sep 8, 2020
1 parent 31a78b5 commit 8c914d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 48 deletions.
46 changes: 0 additions & 46 deletions cachetools/abc.py

This file was deleted.

32 changes: 30 additions & 2 deletions cachetools/cache.py
@@ -1,7 +1,10 @@
from .abc import DefaultMapping
from collections.abc import MutableMapping


class _DefaultSize(object):

__slots__ = ()

def __getitem__(self, _):
return 1

Expand All @@ -12,9 +15,11 @@ def pop(self, _):
return 1


class Cache(DefaultMapping):
class Cache(MutableMapping):
"""Mutable mapping to serve as a simple cache or cache base class."""

__marker = object()

__size = _DefaultSize()

def __init__(self, maxsize, getsizeof=None):
Expand Down Expand Up @@ -73,6 +78,29 @@ def __iter__(self):
def __len__(self):
return len(self.__data)

def get(self, key, default=None):
if key in self:
return self[key]
else:
return default

def pop(self, key, default=__marker):
if key in self:
value = self[key]
del self[key]
elif default is self.__marker:
raise KeyError(key)
else:
value = default
return value

def setdefault(self, key, default=None):
if key in self:
value = self[key]
else:
self[key] = value = default
return value

@property
def maxsize(self):
"""The maximum size of the cache."""
Expand Down

0 comments on commit 8c914d4

Please sign in to comment.