Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsMemoization can speed up a Python function when it is called repeatedly with the same arguments: instead of recalculating a result, Python returns a value saved from an earlier call. Use functools.cache when the set of cached inputs is safely bounded; choose functools.lru_cache when you need to limit how many results stay in memory. Neither is a universal speed boost: the function must be safe to reuse, and the benefit depends on the workload.
How memoization works in Python
A memoized function stores results by call arguments. On a cache hit, the wrapper returns the stored result; on a miss, it calls the original function and saves the result for later. This is most useful when the same inputs recur and the calculation costs more than looking up a result.
Python provides both decorators in functools. The official Python 3.14.8 functools documentation describes the LRU cache as appropriate when you want to reuse previously computed values.
Choose between cache and lru_cache
| Decorator | Storage behavior | When it fits |
|---|---|---|
@cache |
Unbounded; equivalent to @lru_cache(maxsize=None). |
Use when the set of distinct inputs is finite or otherwise safely bounded and you want a lightweight cache without eviction. |
@lru_cache |
Defaults to at most 128 entries; accepts an explicit maximum size and evicts least-recently-used entries when full. | Use when recent inputs are likely to recur and a long-running process needs a cap on retained entries. |
The default of 128 is not a universal tuning target. Set a size based on the workload, the memory cost of cached keys and values, and how often useful inputs recur. A bound that is too small can evict results before they are reused; an unbounded cache can keep growing as new inputs arrive.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
How to add a cache safely
For example, a parser whose output depends only on its schema text could use a bounded cache:
from functools import lru_cache
@lru_cache(maxsize=256)
def parse_schema(schema_text: str) -> object:
...
The example is appropriate only if repeated calls with the same schema text should produce an interchangeable result. If the output can change while the arguments stay the same, caching needs a deliberate invalidation strategy or should not be used.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Cache keys are built from the function’s positional and keyword arguments, which must be hashable. Mutable types such as lists and dictionaries cannot be used directly as arguments to a cached call. Also, calls using the same values but a different keyword-argument order may be treated as separate entries, so normalize call patterns if duplicate entries would undermine reuse.
Cases where memoization causes problems
- Side effects: A cached call is skipped on a hit, so side effects such as writing a file or updating shared state will not happen on every call.
- Changing results: If results depend on current time, external data, or mutable state not included in the arguments, a hit may return stale data. Clear or otherwise invalidate entries when appropriate, or avoid caching.
- Fresh mutable results: A cache returns the same stored object on a hit. Do not cache a function when each call must provide a newly created list, dictionary, or other mutable object.
- Generators and async functions: Caching a generator or coroutine object does not cache a fresh sequence or completed asynchronous result for each invocation. These decorators are not suitable for those use cases.
- Memory retention: Cache entries retain their arguments and results until eviction or clearing. An unbounded cache can grow indefinitely; even a bounded cache retains up to its configured number of entries.
Methods: cached_property or lru_cache?
For a value that belongs to one object and requires no extra call arguments, functools.cached_property is often a better fit: it stores the computed value on that instance. By contrast, decorating a method with lru_cache includes self in the key. The official CPython programming FAQ notes this distinction; cached method entries can keep instances alive until those entries are evicted or the cache is cleared.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Threads and duplicate calculations
The Python Software Foundation’s official documentation says the cache is threadsafe, meaning the wrapped function can be used across multiple threads without corrupting the cache structure. That does not guarantee only one calculation for a missing key: if two threads request the same uncached input at nearly the same time, both may run the underlying function before either result is stored.
Check whether caching helped
Use the wrapper’s cache_info() method to inspect hits, misses, maximum size, and current size. A high hit count suggests repeated calls are being reused, but it does not by itself prove that total runtime improved.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
- Time the uncached function on a representative workload, including realistic repeated and unique inputs.
- Apply
@cacheor@lru_cacheand run the same workload under comparable conditions. - Review
cache_info()and check memory use, output correctness, and whether results need invalidation. - Keep the decorator only if the measured workload benefits without unacceptable memory use or stale results.
To inspect or manage the wrapper, call function.cache_clear() to remove stored entries. The function.__wrapped__ attribute provides access to the original function when you need to call or time it without the cache.
Further reading
For broader coverage of Python decorators and caching, O’Reilly’s publisher page for Fluent Python, 2nd Edition lists material on functools.cache and lru_cache.
Recommended Free Tools
Quick Recap
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

