Skip to content

Instantly share code, notes, and snippets.

@FrostiiWeeb
Created June 27, 2021 08:37
Show Gist options
  • Save FrostiiWeeb/1d65201fd44fee72dc375a82fc6e8a49 to your computer and use it in GitHub Desktop.
Save FrostiiWeeb/1d65201fd44fee72dc375a82fc6e8a49 to your computer and use it in GitHub Desktop.
A example for a simple cache system.
class CacheError(Exception):
def __init__(self, message : str):
super().__init__(message)
class CacheOutput:
def __init__(self, cache_system):
self.cache = cache_system
def replace(self, result_name, result_output):
self.cache._properties[result_name] = result_output
return self
def insert(self, result_name, result_output):
self.cache._properties[result_name] = result_output
return self
def delete(self, result_name):
try:
del self.cache._properties[result_name]
except Exception:
raise CacheError(f"{result_name} is not in the cach.")
else:
return self
def get(self, result_name):
try:
result = self.cache._properties[result_name]
except Exception:
raise CacheError(f"{result_name} is not in the cache.")
else:
return result
class Cache:
def __init__(self):
self._properties = {}
self.properties = CacheOutput(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment