Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

LRU caching with expiration period.

License

NotificationsYou must be signed in to change notification settings

datarootsio/expiring-lru-cache

Repository files navigation

logo

expiring_lru_cache

Maintained by datarootsPython versionsPiPyDownloadsCode style: blackMypy checkedCodecovtest

expiring_lru_cache is a minimal drop-in replacement offunctools.lru_cache. Itallows the user to specify a time interval (in secs) after which the cache isinvalidated and reset.

Usage

Here an example cached function whose cache will invalidate after 10 seconds.

fromexpiring_lru_cacheimportlru_cache@lru_cache(expires_after=10)defmy_plus_one_func(x:int)->int:returnx+1

Here an example cached function whose cache will invalidate after 1 day. Note that theconvenience variablesMINUTES,HOURS andDAYS are available within theexpiring_lru_cache namespace.

fromexpiring_lru_cacheimportlru_cache,DAYS@lru_cache(expires_after=1*DAYS)defmy_plus_one_func(x:int)->int:returnx+1

[8]ページ先頭

©2009-2025 Movatter.jp