Initial Release of IGNCore version 2.5

This commit is contained in:
2021-08-09 13:18:56 +02:00
commit a83d98c47e
910 changed files with 224171 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import os
from pathlib import Path
from core.decorators import instance
from core.dict_object import DictObject
from core.logger import Logger
@instance()
class CacheService:
CACHE_DIR = os.sep + os.path.join("data", "cache")
def __init__(self):
Path(os.getcwd() + self.CACHE_DIR).mkdir(parents=True, exist_ok=True)
self.logger = Logger(__name__)
def store(self, group, filename, contents):
base_path = os.getcwd() + self.CACHE_DIR + os.sep + group
Path(base_path).mkdir(exist_ok=True)
with open(base_path + os.sep + filename, mode="w", encoding="UTF-8") as f:
f.write(contents)
def retrieve(self, group, filename):
base_path = os.getcwd() + self.CACHE_DIR + os.sep + group
full_path = base_path + os.sep + filename
try:
with open(full_path, mode="r", encoding="UTF-8") as f:
last_modified = int(os.path.getmtime(full_path))
return DictObject({"data": f.read(), "last_modified": last_modified})
except FileNotFoundError:
return None