meta: introduce a Cache decorator (MR 2252)

Generalise pmb.helpers.other.cache with a more python decorator.

The Cache decorator takes a list of function arguments to use as cache
keys, keyword args can be used to restrict caching so that it is skipped
entirely unless the attribute has a specific value.

For example, pmb.helpers.pmaports.get() has the decorator:
@Cache("pkgname", subpackages=True)

This means the return value will be cached only when subpackages is
True, otherwise it will always miss.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-09 13:22:58 +02:00 committed by Oliver Smith
parent 79cf2e8910
commit 185d8bcef5
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
20 changed files with 244 additions and 165 deletions

View file

@ -100,7 +100,7 @@ class Chroot:
if not isinstance(other, Chroot):
return NotImplemented
return self.type() == other.type() and self.name() == other.name()
return self.type == other.type and self.name() == other.name()
def __truediv__(self, other: object) -> Path:
@ -129,6 +129,7 @@ class Chroot:
return NotImplemented
@property
def type(self) -> ChrootType:
return self.__type