Top Tweets for #lru_cache
Handy syntax reference lookup for clean code execution. For caching expensive backend processing functions in Python, do you prefer lru_cache or manual state dicts?
https://t.co/UMlyd7xX35
Modern Python features like structural pattern matching and `lru_cache` eliminate massive amounts of boilerplate code.
In production backend services today, do you use `match/case` blocks or stick to `if/elif` chains?

• Caching is useful when we want to optimize performance when computationally intensive operations are repeated on the same data.
• Python has two decorators to create a cache when calling functions: `lru_cache` and `cache` in the functools module
• lru_cache has been available since Python 3.2 & cache is newer which is available since Python 3.9
python decorators are a gem but lru_cache has to be mentioned

Just replaced my manual DP memoization (lists/dicts) with lru_cache in Python and it's so clean and cooool!!
If your FastAPI app is slowing down, add:
✅ @lru_cache
✅ async def endpoints
✅ background tasks
✅ proper DB pooling
❌ more features
#FastAPI #Performance #BackendTips
🚀 Speed up slow Python functions with one line.
@lru_cache remembers results of expensive calls.
Perfect for:
- API clients
- DB queries
- Recursion
- Config loaders
Use it where input repeats and performance matters.
Have you tried it yet?
#Python #DevTips #Tech

Bonus: Time-based caching?
lru_cache is great, but not time-aware.
For time-expiry, use:
- cachetools with TTL
- Custom wrapper using timestamps
- joblib.Memory for disk persistence
Basic example: Fibonacci
Without caching? Slow.
With lru_cache? Near-instant 🚀

What is lru_cache?
lru_cache stands for Least Recently Used Cache.
It’s a decorator that automatically remembers the results of function calls.
If a function is called again with the same inputs, the result is returned instantly.
📦 Built into Python since 3.2.
Want to make your Python code faster without changing much?
Enter: functools.lru_cache - a built-in, zero-dependency caching tool 🔥
This thread covers:
- How lru_cache works
- Real use cases
- Performance tips & gotchas
Let’s memoize! 🧵👇
@joseph_h_garvin But yeah. O(1) in python with lru_cache is fine, but in C++ you should use true O(1) - a single pointer dereference
Boost the performance of your recursive functions or any time-consuming function using the lru_cache decorator!
lru_cache caches the results of expensive function calls and returns the cached result when the same inputs occur again.
@lru_cache0 @MaximeMB_ wow has anyone ever told you that you look exactly like zuck in your pfp?
i nominate u lru cache
Last Seen Hashtags on Sotwe
Trends for you
Most Popular Users

Elon Musk 
@elonmusk
239.6M followers

Barack Obama 
@barackobama
118.6M followers

Cristiano Ronaldo 
@cristiano
114.3M followers

Donald J. Trump 
@realdonaldtrump
111.7M followers

Narendra Modi 
@narendramodi
106.9M followers

Rihanna 
@rihanna
98.6M followers

NASA 
@nasa
92.1M followers

Justin Bieber 
@justinbieber
91.7M followers

KATY PERRY 
@katyperry
89.9M followers

Taylor Swift 
@taylorswift13
83.9M followers

Lady Gaga 
@ladygaga
75.4M followers

Virat Kohli 
@imvkohli
73.3M followers

Kim Kardashian 
@kimkardashian
70.8M followers

YouTube 
@youtube
68.6M followers

Neymar Jr 
@neymarjr
66.3M followers

Bill Gates 
@billgates
65.1M followers

Selena Gomez 
@selenagomez
63M followers

The Ellen Show
@theellenshow
62.1M followers

CNN 
@cnn
61.7M followers

X 
@x
60.6M followers










