From c56b8a2473c8004fa65aba23b47d4afcbc9e5f09 Mon Sep 17 00:00:00 2001 From: Sebastian <118485377+spalencsar@users.noreply.github.com> Date: Sat, 27 Jun 2026 10:06:05 +0200 Subject: [PATCH] refactor: migrate native modules from bauh/ to bearhub/ (test batch) --- .gitignore | 1 + bearhub/api/abstract/cache.py | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 bearhub/api/abstract/cache.py diff --git a/.gitignore b/.gitignore index 799515db..b0a7c311 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ AGENTS.md packaging/aur/**/*.tar.gz packaging/aur/**/src packaging/aur/**/pkg + diff --git a/bearhub/api/abstract/cache.py b/bearhub/api/abstract/cache.py new file mode 100644 index 00000000..c0bcabcf --- /dev/null +++ b/bearhub/api/abstract/cache.py @@ -0,0 +1,50 @@ +from abc import ABC, abstractmethod +from typing import Set, Optional + + +class MemoryCache(ABC): + """ + Represents a memory cache. + """ + + @abstractmethod + def is_enabled(self): + pass + + @abstractmethod + def add(self, key: str, val: object): + pass + + @abstractmethod + def add_non_existing(self, key: str, val: object): + pass + + @abstractmethod + def get(self, key: str): + pass + + @abstractmethod + def delete(self, key): + pass + + @abstractmethod + def keys(self) -> Set[str]: + pass + + @abstractmethod + def clean_expired(self): + pass + + +class MemoryCacheFactory(ABC): + """ + Instantiate new memory cache instances. + """ + + @abstractmethod + def new(self, expiration: Optional[int]) -> MemoryCache: + """ + :param expiration: expiration time for the cache keys in seconds. Use -1 to disable this feature. + :return: + """ + pass