Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.200.760 Times

PyLRU 1.0.1

Company: Jay Hutchinson
Date Added: June 08, 2013  |  Visits: 431

PyLRU

Report Broken Link
Printer Friendly Version


Product Homepage
Download (39 downloads)



A least recently used (LRU) cache for Python.<br /><br />Pylru implements a true LRU cache along with several support classes. The cache is efficient and written in pure Python. It works with Python 2.6+ including the new 3.x series. Basic operations (lookup, insert, delete) all run in a constant amount of time.<br /><br /><br />Usage<br />=====<br /><br />You can install pylru, or you can just copy the source file pylru.py and use it in your own project.<br /><br />An LRU cache object has a dictionary like interface and can be used in the same way::<br /><br /> import pylru<br /> <br /> size = 100<br /> cache = pylru.lrucache(size)<br /><br /> cache[key] = value # Add a key/value pair<br /> key in cache # Test for membership<br /> value = cache[key] # Lookup a value given its key<br /> del cache[key] # Remove a value given its key<br /><br /> cache.size() # Returns the size of the cache<br /> cache.size(x) # Changes the size of the cache. x MUST be greater than<br /> # zero.<br /> <br /> x = len(cache) # Returns the number of elements stored in the cache.<br /> # x will be less than or equal to cache.size() <br /> <br /> cache.clear() # Remove all elements from the cache.<br /> <br />The lrucache takes an optional callback function as a second argument. Since the cache has a fixed size some operations, such as an insertion, may cause a key/value pair to be ejected. If the optional callback function is given it will be called when this occurs. For example::<br /><br /> import pylru<br /> <br /> def callback(key, value):<br /> print (key, value) # A dumb callback that just prints the key/value<br /> <br /> size = 100<br /> cache = pylru.lrucache(size, callback)<br /> <br /> # Use the cache... When it gets full some pairs may be ejected due to<br /> # the fixed cache size. But, not before the callback is called to let you<br /> # know.<br /> <br />Often a cache is used to speed up access to some other low latency object. If that object has a dictionary interface a convenience wrapper class provided by PyLRU can be used. This class takes as an argument the object you want to wrap and the cache size. It then creates an LRU cache for the object and automatically manages it. For example, imagine you have an object with a dictionary interface that reads/writes its values to and from a remote server. Let us call this object slowDict::<br /><br /> import pylru<br /> <br /> size = 100<br /> cacheDict = pylru.lruwrap(slowDict, size)<br /> <br /> # Now cacheDict can be used just like slowDict, except all of the lookups<br /> # are automatically cached for you using an LRU cache.<br /> <br />By default lruwrap uses write-through semantics. For instance, in the above example insertions are updated in the cache and written through to slowDict immediatly. The cache and the underlying object are not allowed to get out of sync. So only lookup performace can be improved by the cache. lruwrap takes an optional third argument. If set to True write-back semantics will be used. Insertions will be updated to the cache. The underlying slowDict will automatically be updated only when a "dirty" key/value pair is ejected from the cache.<br /><br />The programmer is responsible for one thing though. They MUST call sync() when they are finished. This ensures that the last of the "dirty" entries in the cache are written back::<br /><br /><br /> import pylru<br /> <br /> size = 100<br /> cacheDict = pylru.lruwrap(slowDict, size, True)<br /> <br /> # Now cacheDict can be used just like slowDict, except all of the lookups<br /> # are automatically cached for you using an LRU cache with Write-Back<br /> # semantics.<br /><br /> # DON'T forget to call sync() when finished<br /> cacheDict.sync()<br /> <br />To help the programmer with this the lruwrap can be used in a with statement::<br /> <br /> with pylru.lruwrap(slowDict, size, True) as cacheDict<br /> <br /> # Use cacheDict, sync() is called automatically for you when leaving the<br /> # with statment block.<br /><br /><br />PyLRU also provides a function decorator::<br /><br /> from pylru import lrudecorator<br /><br /> @lrudecorator(100)<br /> def square(x):<br /> return x*x<br /> <br /> # Now results of the square function are cached for future lookup.<br /><br />#md5=fdfc930b645d572e02ea5b48577ea12b

Requirements: No special requirements
Platforms: *nix, Linux
Keyword: Automatically Cache Cachedict Cachekey Callback Called Dictionary Ejected Function Import Interface Keyvalue Object Pylru Semantics Slowdict Updated
Users rating: 0/10

License: Freeware Size: 10.24 KB
USER REVIEWS
More Reviews or Write Review


PYLRU RELATED
Modules  -  AHAH Action 6.x-1.0
This is a helper module that allows the returned data from an AHAH callback to specify the function to be called. It also allows an additional function to be called before AHAH submission. This module is used by the Autotag module.Development of...
10 KB  
Modules  -  Auto locale import 5.x-1.x-de
The autolocale module and enclosed localized install profile provides a profile to automatically import interface translations in install time and later when modules are enabled / disabled.Most of the module's functionality (with better...
20.48 KB  
Utilities  -  CrystalDMI 1.0.6
CrystalDMI is a useful application that gets BIOS / System / Base Board / Processor / Memory Controller / Memory Module / Cache or Port Connector Information by DMI (Desktop management Interface). Features: · BIOS Information · System...
184 KB  
Modules  -  Live Search Popup 1.4.7
It can be used a widget or called as a function from the template.InstallationUnpack and upload it to the /wp-content/plugins/ directory.Activate the plugin through the 'Plugins' menu in WordPress. Requirements: - WordPress 2.0.2 or higher
 
Language  -  Everest Dictionary with databases 3.10
It is the greatest free dictionary. For the time being, it includes 31 dictionaries. The producer assured us that soon he will contribute with other some dictionaries. The facilities of this dictionary: - It contain all international...
79.28 MB  
Libraries  -  Callback 1.07
Callback is an object interface for function callbacks. SYNOPSIS use Callback; my $callback = new Callback (&myfunc, @myargs); my $callback = new Callback ($myobj, $mymethod, @myargs); my $callback = new Callback ($old_callback, @myargs);...
4.1 KB  
Libraries  -  CGI::Cache 1.4200
CGI::Cache is a Perl extension to help cache output of time-intensive CGI scripts. WARNING The interface as of version 1.01 has changed considerably and is NOT compatible with earlier versions. A smaller interface change also occurred in...
44.03 KB  
Modules  -  GTalk Status to WordPress 0.12
This plugin will automatically show your GTalk status on your WordPress blog. You can set a max-shown number and the cache interval to make it works more smoothly.FYI:The principle of this plugin is to refine your GTalk badge page, which is the...
10 KB  
Modules  -  Hot Linked Image Cacher 1.01
You can control exactly which post to cache by optionally specifying a post id number (or just put all to cache all posts). You can also control exactly which domain to cache from by specifying domains. This plugin supports both curl and...
 
Development Tools  -  uispinner 1.0
GUI control to allow user to input a scalar. The callback is called continuously as the user steps the spinner. For example if the value was contrast in an image-processing application, the image could update as the user presses on the control.
10 KB  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
Linux Software  -  EasyEDA PCB Designer for Linux 2.0.0
EasyEDA, a great web based EDA(Electronics Design Automation) tool, online PCB tool, online PCB software for electronics engineers, educators, students, makers and enthusiasts. Theres no need to install any software. Just open EasyEDA in any...
34.4 MB  
Linux Software  -  wpCache® WordPress HTTP Cache 1.9
wpCache® is a high-performance, distributed object, caching system application, generic in nature, but intended for use in speeding up dynamic web applications, by decreasing database load time. wpCache® decreases dramatically the page...
3.51 MB  
Linux Software  -  Polling Autodialer Software 3.4
ICTBroadcast Auto Dialer software has a survey campaign for telephone surveys and polls. This auto dialer software automatically dials a list of numbers and asks them a set of questions that they can respond to, by using their telephone keypad....
488 B  
Linux Software  -  Total Video Converter Mac Free 3.5.5
Total Video Converter Mac Free developed by EffectMatrix Ltd is the official legal version of Total Video Converter which was a globally recognized brand since 2006. Total Video Converter Mac Free is a free but powerful all-in-one video...
17.7 MB  
Linux Software  -  Skeith mod_log_sql Analyzer 2.10beta2
Skeith is a php based front end for analyzing logs for Apache using mod_log_sql.
47.5 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB