{"id":22459,"library":"theine-core","title":"Theine Cache","description":"Theine is a high-performance, in-memory cache library for Python with support for TTL, LRU, LFU, and windowed TinyLFU eviction policies. Current version 2.1.0 requires Python >=3.10 and is actively maintained.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/kayembi/theine","tags":["cache","lru","lfu","tinylfu","in-memory"],"install":[{"cmd":"pip install theine-core","lang":"bash","label":"install from PyPI"}],"dependencies":[],"imports":[{"wrong":"from theine import Cache","symbol":"Cache","correct":"from theine_core import TlfuCore"},{"symbol":"BloomFilter","correct":"from theine_core import BloomFilter"},{"symbol":"spread","correct":"from theine_core import spread"}],"quickstart":{"code":"from theine import Cache\n\ncache = Cache(\"lru\", maxsize=100, ttl=60)\ncache.set(\"key\", \"value\")\nprint(cache.get(\"key\"))  # 'value'\n\n# Context manager\nwith Cache(\"tinylfu\", maxsize=1000) as c:\n    c.set(\"a\", 1)\n    print(c.get(\"a\"))  # 1","lang":"python","description":"Basic LRU cache with TTL and a context manager example."},"warnings":[{"fix":"Use 'from theine import Cache' (not theine-core, not theine_core).","message":"The package name is 'theine-core' on PyPI, but the import module is 'theine'. Many users mistakenly import from 'theine_core' or 'theine.core'.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'maxsize' instead of 'max_size'. Also, the 'ttl' parameter now expects seconds as an integer, not a timedelta.","message":"In version 2.x, the API changed: The Cache class no longer accepts 'policy' as a string like 'lru' directly? Verify: Actually it does. But the 'maxsize' parameter was renamed from 'max_size' in v1.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use external locking if you need concurrent writes, or consider a thread-safe cache like cachetools.","message":"Theine's thread-safety is limited: concurrent writes from multiple threads may cause race conditions. The documentation notes that Cache is not thread-safe for writes.","severity":"gotcha","affected_versions":"all"},{"fix":"Set maxsize to a power of two (e.g., 1024, 2048) when using 'tinylfu' or 'windowed_tinylfu'.","message":"When using 'tinylfu' policy, the 'maxsize' must be a power of two for optimal performance; otherwise it may degrade.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'2.1.0':29 '3.10':32 'activ':35 'cach':2,12,37 'current':27 'evict':25 'high':7 'high-perform':6 'in-memori':9,41 'lfu':21,39 'librari':13 'lru':20,38 'maintain':36 'memori':11,43 'perform':8 'polici':26 'python':15,31 'requir':30 'support':17 'thein':1,3 'tinylfu':24,40 'ttl':19 'version':28 'window':23","created_at":"2026-04-27T17:05:17.028611+00:00","updated_at":"2026-04-27T17:05:17.028611+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/theine-core/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}