Skip to content

Commit

Permalink
Feature optimize cache (#4)
Browse files Browse the repository at this point in the history
* Add code of conduct

* Optimize cache usage

Just a foolproof. There is no need to have infinite
cache.

* Remove outdated code
  • Loading branch information
koldakov committed Mar 18, 2024
1 parent d3de760 commit 218f1a6
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/pycountries/currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,20 @@

from decimal import Decimal
from enum import Enum
from functools import singledispatchmethod
from functools import lru_cache, singledispatchmethod

from pydantic import Field

from pycountries._base import EnumTypeBase, UnitBase

try:
from functools import cache
except ImportError:
from functools import lru_cache

def cache( # type: ignore[misc]
user_function,
/,
):
"""
https://github.com/python/cpython/commit/21cdb711e3b1975398c54141e519ead02670610e
"""
return lru_cache(maxsize=None)(user_function)


class CurrencyUnit(UnitBase):
digits: int = Field(
default=2,
)


@cache
@lru_cache(maxsize=3)
def _get_currencies_by_digits(
digits: int,
/,
Expand Down

0 comments on commit 218f1a6

Please sign in to comment.