Access to a shared cache from multiple threads must be properly synchronized, e. This class discards arbitrary items using popitem to make space when necessary. Derived classes may override popitem to implement specific caching strategies.
This class counts how often an item is retrieved, and discards the items used least often to make space when necessary. By default, items are selected from the list of cache keys using random.
The optional argument choice may specify an alternative function that returns an arbitrary element from a non-empty sequence. This class associates a time-to-live value with each item. Items that expire because they have exceeded their time-to-live will be no longer accessible, and will be removed eventually.
If no expired items are there to remove, the least recently used items will be discarded first to make space when necessary. By default, the time-to-live is specified in seconds and time. A custom timer function can also be supplied:. Expired items will be removed from a cache only at the next mutating operation, e. Calling this method removes all items whose time-to-live would have expired by time , so garbage collection is free to reuse their memory.
If time is None , this removes all items that have expired by the current value returned by timer. Remove and return the key, value pair least recently used that has not already expired. Similar to TTLCache , this class also associates an expiration time with each item. The expression ttu key, value, timer defines the expiration time of a cache item, and must be comparable against later results of timer.
Items that expire because they have exceeded their time-to-use will be no longer accessible, and will be removed eventually. Calling this method removes all items whose time-to-use would have expired by time , so garbage collection is free to reuse their memory. Sometimes it may be desirable to notice when and what cache items are evicted, i.
Since all cache implementations call popitem to evict items from the cache, this can be achieved by overriding this method in a subclass:. Note, though, that such a class does not really behave like a cache any more, and will lead to surprising results when used with any of the memoizing decorators described below.
However, it may be useful in its own right. The cachetools module provides decorators for memoizing function and method calls. This can save time when a function is often called with the same arguments:. The cache argument specifies a cache object to store previous function arguments and return values.
Note that cache need not be an instance of the cache implementations provided by the cachetools module. So it's an ideal tool to document steps and procedures on the fly, while you're executing. Although it's a very handy tool and quick and easy to use, one of the disadvantages is that it does not capture keystrokes.
Another disadvantage is that PSR is taken full-screen snapshots, but you can solve this to edit the saved file, extract or edit the images and resave the document. You must make sure to set the number of screenshots at a sufficiently high level. A note of advice: set it to the maximum. You can temporarily stop recording by hitting the pause button when you don't want to record some steps, or you need to fix something before continuing recording. Additionally, the webserver may be listening in another port.
This is an example for running cachetool from the webserver host in such a setup:. You can have a configuration file with the adapter configuration, allowing you to call CacheTool without --fcgi , --cli , or --web option. The file must be named. CacheTool will look for this file on the current directory and in any parent directory until it finds one. You can define the supported extensions in the config file.
By default, apcu , and opcache are enabled. To disable apcu , add this to your config file:.
0コメント