mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Remove unused 'Cache.protect' method
This commit is contained in:
parent
7fa1501112
commit
f106923f17
@ -61,7 +61,6 @@ class Cache(object):
|
|||||||
self.min_time = min_time
|
self.min_time = min_time
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
self._auto_prune = auto_prune
|
self._auto_prune = auto_prune
|
||||||
self._protected = dict()
|
|
||||||
self._lock = threading.RLock()
|
self._lock = threading.RLock()
|
||||||
|
|
||||||
# Create the cache directory
|
# Create the cache directory
|
||||||
@ -119,24 +118,6 @@ class Cache(object):
|
|||||||
"""The current amount of data cached"""
|
"""The current amount of data cached"""
|
||||||
return self._size
|
return self._size
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def protect(self, key):
|
|
||||||
"""Protect a file from being purged from the cache
|
|
||||||
|
|
||||||
Ex:
|
|
||||||
>>> with cache.protect(key):
|
|
||||||
... cache.delete(key)
|
|
||||||
ProtectedError: File is protected from deletion
|
|
||||||
"""
|
|
||||||
with self._lock:
|
|
||||||
self._protected[key] = self._protected.get(key, 0) + 1
|
|
||||||
yield
|
|
||||||
with self._lock:
|
|
||||||
if self._protected[key] <= 1:
|
|
||||||
del self._protected[key]
|
|
||||||
else:
|
|
||||||
self._protected[key] -= 1
|
|
||||||
|
|
||||||
def touch(self, key):
|
def touch(self, key):
|
||||||
"""Mark a cache entry as fresh"""
|
"""Mark a cache entry as fresh"""
|
||||||
with self._lock:
|
with self._lock:
|
||||||
@ -215,8 +196,6 @@ class Cache(object):
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
if not self.has(key):
|
if not self.has(key):
|
||||||
return
|
return
|
||||||
if key in self._protected:
|
|
||||||
raise ProtectedError("File is protected from deletion")
|
|
||||||
if time() < self._files[key].expires:
|
if time() < self._files[key].expires:
|
||||||
raise ProtectedError("File has not expired")
|
raise ProtectedError("File has not expired")
|
||||||
|
|
||||||
|
@ -218,35 +218,6 @@ class CacheTestCase(unittest.TestCase):
|
|||||||
cache.set("key", val_small)
|
cache.set("key", val_small)
|
||||||
self.assertEqual(cache.size, 1)
|
self.assertEqual(cache.size, 1)
|
||||||
|
|
||||||
def test_protected(self):
|
|
||||||
cache = Cache(self.__dir, 20, min_time=0)
|
|
||||||
val = b'0123456789'
|
|
||||||
|
|
||||||
with cache.protect("key1"):
|
|
||||||
cache.set("key1", val)
|
|
||||||
cache.set("key2", val)
|
|
||||||
cache.set("key3", val)
|
|
||||||
|
|
||||||
self.assertTrue(cache.has("key1"))
|
|
||||||
self.assertFalse(cache.has("key2"))
|
|
||||||
self.assertTrue(cache.has("key3"))
|
|
||||||
|
|
||||||
def test_multi_protect(self):
|
|
||||||
cache = Cache(self.__dir, 10, min_time=0)
|
|
||||||
val = b'0123456789'
|
|
||||||
cache.set("key", val)
|
|
||||||
with cache.protect("key"):
|
|
||||||
with self.assertRaises(ProtectedError):
|
|
||||||
cache.delete("key")
|
|
||||||
|
|
||||||
with cache.protect("key"):
|
|
||||||
with self.assertRaises(ProtectedError):
|
|
||||||
cache.delete("key")
|
|
||||||
|
|
||||||
with self.assertRaises(ProtectedError):
|
|
||||||
cache.delete("key")
|
|
||||||
cache.delete("key")
|
|
||||||
|
|
||||||
def test_no_auto_prune(self):
|
def test_no_auto_prune(self):
|
||||||
cache = Cache(self.__dir, 10, min_time=0, auto_prune=False)
|
cache = Cache(self.__dir, 10, min_time=0, auto_prune=False)
|
||||||
val = b'0123456789'
|
val = b'0123456789'
|
||||||
@ -260,25 +231,6 @@ class CacheTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(cache.size, 10)
|
self.assertEqual(cache.size, 10)
|
||||||
|
|
||||||
def test_clear(self):
|
|
||||||
cache = Cache(self.__dir, 40, min_time=0)
|
|
||||||
val = b'0123456789'
|
|
||||||
|
|
||||||
with cache.protect("key1"):
|
|
||||||
cache.set("key1", val)
|
|
||||||
cache.set("key2", val)
|
|
||||||
cache.set("key3", val)
|
|
||||||
cache.set("key4", val)
|
|
||||||
self.assertEqual(cache.size, 40)
|
|
||||||
|
|
||||||
cache.clear()
|
|
||||||
|
|
||||||
self.assertEqual(cache.size, 10)
|
|
||||||
self.assertTrue(cache.has("key1"))
|
|
||||||
|
|
||||||
cache.clear()
|
|
||||||
self.assertEqual(cache.size, 0)
|
|
||||||
|
|
||||||
def test_min_time_clear(self):
|
def test_min_time_clear(self):
|
||||||
cache = Cache(self.__dir, 40, min_time=1)
|
cache = Cache(self.__dir, 40, min_time=1)
|
||||||
val = b'0123456789'
|
val = b'0123456789'
|
||||||
|
Loading…
Reference in New Issue
Block a user