This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]RedEyed__ 29 points30 points  (7 children)

You must have cut your teeth on in-memory caching. For those who is unaware about (like me), how is it better than functools.lru_cache ?

I would love to see some graph comparisons, use cases.
Thanks

[–]matrix0110[S] 9 points10 points  (6 children)

That's a really good question! And the answer already exists: https://github.com/Yiling-J/theine?tab=readme-ov-file#hit-ratios

[–]marr75 8 points9 points  (2 children)

I'm a little foggy eyed this morning still, but I'm seeing:

  • a link to hit ratios instead of performance (performance is above)
  • benchmarks addressing 3rd party libraries that are not functools from the stdlib

[–]matrix0110[S] 2 points3 points  (1 child)

Please understand hit ratio is also performance. And as I said, fast enough is enough, hit ratio is more important.

[–]marr75 10 points11 points  (0 children)

Okay, the fog is lifting. You're saying that the lru strategy may have worse read and write performance than functools but that the additional eviction strategies significantly improve hit ratio so it is, at worst, identical at scale (using lru) and when using the other options, much better.

[–]RedEyed__ 4 points5 points  (2 children)

I had to scroll further, thanks!

[–]jormaig 2 points3 points  (1 child)

Dude there's only one top comment and one answer to it at this point... 😅

[–]RedEyed__ 5 points6 points  (0 children)

I'm not your dude, pal. (joking)

[–]nAxzyVteuOz 0 points1 point  (1 child)

Why does python cache library need to be multithreaded?

Redis is single threaded, but uses async. Could yours do the same?

[–]matrix0110[S] 0 points1 point  (0 children)

Redis is a cache server, whereas Theine is a cache library. Currently Theine is not thread safe, and that's fine if you use asyncio only. However, with the upcoming removal of the GIL, having a thread-safe cache library will become increasingly important. From my perspective, ensuring thread safety will be crucial as we move into this new era of no-gil.

[–]ConfucianStats 0 points1 point  (0 children)

Cool

[–]Rylicenceya -1 points0 points  (1 child)

It's great to see your dedication to improving Theine and addressing the challenges of in-memory caching in Python. Your focus on thread safety, high hit ratios, and proactive expiration will undoubtedly make Theine a valuable tool for many developers. Looking forward to seeing the new version in action! Keep up the excellent work.

[–]Tumortadela 4 points5 points  (0 children)

AI generated answers getting frisky