Closed lasuk closed 2 months ago
Let's extend the cache to currencies, since currency lookup is also a frequent trigger for an (avoidable) API request.
Steps:
CashCtrlClient.list_currencies()
, similar to CashCtrlClient.list_tax_codes()
.CachedCashCtrlClient
to include list_currencies()
and the related mapping functions currency_from_id
and currency_to_id
.Implemented as #29
Description: I would like to request a feature that implements caching for the
list_accounts
andlist_tax_codes
methods in theCashCtrlClient
class. This enhancement aims to reduce the number of API calls by caching the data on the first lookup and reusing the cached data for subsequent calls within a specified timeout period.Proposed Solution: A new class,
CachedCashCtrlClient
, extendsCashCtrlClient
and overrides thelist_accounts
andlist_tax_codes
methods to include caching functionality. The cache timeout can be configured during class initialization or adjusted later through a property.In addition, I propose to provide lookup functions to map account numbers to account ids, or tax code names to tax ids, and vice versa.
account_to_id(account: float) -> int
account_from_id(id: int) -> float
tax_code_to_id(code: str) -> int
tax_code_from_id(id: int) -> str
A first implementation is available in the
feat/cache
branch and can be reviewed here: CachedCashCtrlClient ImplementationDetails:
cache_timeout
parameter (default is 300 seconds).list_accounts
,list_tax_codes
._is_expired
method.cache_timeout
property.Usage Example: