Rename self._meta to self._meta_cache and self._etag to self._etag_cache

This commit is contained in:
Unrud 2017-06-09 02:30:57 +02:00 committed by Unrud
parent 12871fdcb3
commit 79e7232ecb

View File

@ -544,8 +544,8 @@ class Collection(BaseCollection):
split_path = self.path.split("/") split_path = self.path.split("/")
self.owner = split_path[0] if len(split_path) > 1 else None self.owner = split_path[0] if len(split_path) > 1 else None
self.is_principal = principal self.is_principal = principal
self._meta = None self._meta_cache = None
self._etag = None self._etag_cache = None
@classmethod @classmethod
def _get_collection_root_folder(cls): def _get_collection_root_folder(cls):
@ -1151,16 +1151,16 @@ class Collection(BaseCollection):
def get_meta(self, key=None): def get_meta(self, key=None):
# reuse cached value if the storage is read-only # reuse cached value if the storage is read-only
if self._writer or self._meta is None: if self._writer or self._meta_cache is None:
try: try:
with open(self._props_path, encoding=self.encoding) as f: with open(self._props_path, encoding=self.encoding) as f:
self._meta = json.load(f) self._meta_cache = json.load(f)
except FileNotFoundError: except FileNotFoundError:
self._meta = {} self._meta_cache = {}
except ValueError as e: except ValueError as e:
raise RuntimeError("Failed to load properties of collect" raise RuntimeError("Failed to load properties of collect"
"ion %r: %s" % (self.path, e)) from e "ion %r: %s" % (self.path, e)) from e
return self._meta.get(key) if key else self._meta return self._meta_cache.get(key) if key else self._meta_cache
def set_meta(self, props): def set_meta(self, props):
new_props = self.get_meta() new_props = self.get_meta()
@ -1238,12 +1238,12 @@ class Collection(BaseCollection):
@property @property
def etag(self): def etag(self):
# reuse cached value if the storage is read-only # reuse cached value if the storage is read-only
if self._writer or self._etag is None: if self._writer or self._etag_cache is None:
etag = md5() etag = md5()
for item in self.get_all(): for item in self.get_all():
etag.update((item.href + "/" + item.etag).encode("utf-8")) etag.update((item.href + "/" + item.etag).encode("utf-8"))
self._etag = '"%s"' % etag.hexdigest() self._etag_cache = '"%s"' % etag.hexdigest()
return self._etag return self._etag_cache
_lock = threading.Lock() _lock = threading.Lock()
_waiters = [] _waiters = []