Add some warnings around cache invalidation when mutating items
This commit is contained in:
parent
2e5d51b0af
commit
f36350ebee
@ -69,6 +69,8 @@ class Library:
|
|||||||
def __setitem__(self, key: str, value: PatternGenerator) -> None:
|
def __setitem__(self, key: str, value: PatternGenerator) -> None:
|
||||||
self.primary[key] = value
|
self.primary[key] = value
|
||||||
if key in self.cache:
|
if key in self.cache:
|
||||||
|
logger.warning(f'Replaced library item "{key}" & existing cache entry.'
|
||||||
|
' Previously-generated Pattern will *not* be updated!')
|
||||||
del self.cache[key]
|
del self.cache[key]
|
||||||
|
|
||||||
def __delitem__(self, key: str) -> None:
|
def __delitem__(self, key: str) -> None:
|
||||||
@ -78,6 +80,8 @@ class Library:
|
|||||||
del self.secondary[key]
|
del self.secondary[key]
|
||||||
|
|
||||||
if key in self.cache:
|
if key in self.cache:
|
||||||
|
logger.warning(f'Deleting library item "{key}" & existing cache entry.'
|
||||||
|
' Previously-generated Pattern may remain in the wild!')
|
||||||
del self.cache[key]
|
del self.cache[key]
|
||||||
|
|
||||||
def __getitem__(self, key: str) -> 'Pattern':
|
def __getitem__(self, key: str) -> 'Pattern':
|
||||||
@ -113,6 +117,13 @@ class Library:
|
|||||||
self.cache[key2] = pat
|
self.cache[key2] = pat
|
||||||
return pat
|
return pat
|
||||||
|
|
||||||
|
def set_secondary(self, key: str, tag: str, value: PatternGenerator) -> None:
|
||||||
|
self.secondary[(key, tag)] = value
|
||||||
|
if (key, tag) in self.cache:
|
||||||
|
logger.warning(f'Replaced library item "{key}" & existing cache entry.'
|
||||||
|
' Previously-generated Pattern will *not* be updated!')
|
||||||
|
del self.cache[(key, tag)]
|
||||||
|
|
||||||
def resolve_subpatterns(self, pat: 'Pattern', tag: str) -> 'Pattern':
|
def resolve_subpatterns(self, pat: 'Pattern', tag: str) -> 'Pattern':
|
||||||
logger.debug(f'Resolving subpatterns in {pat.name}')
|
logger.debug(f'Resolving subpatterns in {pat.name}')
|
||||||
for sp in pat.subpatterns:
|
for sp in pat.subpatterns:
|
||||||
@ -293,6 +304,19 @@ class Library:
|
|||||||
del self.cache[key2]
|
del self.cache[key2]
|
||||||
|
|
||||||
|
|
||||||
|
def clear_cache(self: L) -> L:
|
||||||
|
"""
|
||||||
|
Clear the cache of this library.
|
||||||
|
This is usually used before modifying or deleting cells, e.g. when merging
|
||||||
|
with another library.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
self
|
||||||
|
"""
|
||||||
|
self.cache = {}
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
r"""
|
r"""
|
||||||
# Add a filter for names which aren't added
|
# Add a filter for names which aren't added
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user