Implemented SheerkaOntology
This commit is contained in:
Vendored
+27
-5
@@ -1,4 +1,6 @@
|
||||
from cache.Cache import BaseCache
|
||||
from core.global_symbols import Removed, NotFound
|
||||
from core.utils import sheerka_deepcopy
|
||||
|
||||
|
||||
class ListCache(BaseCache):
|
||||
@@ -8,12 +10,17 @@ class ListCache(BaseCache):
|
||||
Items of this cache are list
|
||||
"""
|
||||
|
||||
def _put(self, key, value):
|
||||
def _put(self, key, value, alt_sdp):
|
||||
if key in self._cache:
|
||||
self._cache[key].append(value)
|
||||
else:
|
||||
self._sync(key)
|
||||
|
||||
if key not in self._cache and alt_sdp and not self._is_cleared:
|
||||
previous = self._alt_sdp_get(alt_sdp, key)
|
||||
if previous not in (NotFound, Removed):
|
||||
self._cache[key] = sheerka_deepcopy(previous)
|
||||
|
||||
if key in self._cache:
|
||||
self._cache[key].append(value)
|
||||
else:
|
||||
@@ -22,18 +29,33 @@ class ListCache(BaseCache):
|
||||
self._add_to_add(key)
|
||||
return True
|
||||
|
||||
def _update(self, old_key, old_value, new_key, new_value):
|
||||
def _update(self, old_key, old_value, new_key, new_value, alt_sdp):
|
||||
self._sync(old_key, new_key)
|
||||
|
||||
if old_key not in self._cache and alt_sdp and not self._is_cleared:
|
||||
# no value found in local cache or remote repository
|
||||
# Use the values from alt_sdp
|
||||
previous = self._alt_sdp_get(alt_sdp, old_key)
|
||||
if previous in (NotFound, Removed):
|
||||
raise KeyError(old_key)
|
||||
|
||||
self._cache[old_key] = sheerka_deepcopy(previous)
|
||||
self._current_size += len(previous)
|
||||
|
||||
if old_key != new_key:
|
||||
self._cache[old_key].remove(old_value)
|
||||
if len(self._cache[old_key]) == 0:
|
||||
del (self._cache[old_key])
|
||||
self._add_to_remove(old_key)
|
||||
if not self._is_cleared and alt_sdp and self._extend_exists(alt_sdp, old_key):
|
||||
self._cache[old_key] = Removed
|
||||
self._add_to_add(old_key)
|
||||
self._current_size += 1
|
||||
else:
|
||||
del (self._cache[old_key])
|
||||
self._add_to_remove(old_key)
|
||||
else:
|
||||
self._add_to_add(old_key)
|
||||
|
||||
self._put(new_key, new_value)
|
||||
self._put(new_key, new_value, alt_sdp)
|
||||
self._add_to_add(new_key)
|
||||
else:
|
||||
for i in range(len(self._cache[new_key])):
|
||||
|
||||
Reference in New Issue
Block a user