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

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

Serving Software Downloads in 976 Categories, Downloaded 30.067.543 Times

PyLRU 1.0.1

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

PyLRU

Report Broken Link
Printer Friendly Version


Product Homepage
Download (16 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
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  
Reference  -  Chinese Idiom Dictionary - 50000+ idioms With Fast Search Engine Offline Dict Free HD 1.1
Chinese Idiom Dictionary contains 50,000+ idioms and provides fast search function. Each idiom has phonetics, detailed explanation, derivation and samples. Chinese Idiom Dictionary offers function of favorite, any idiom can be added or...
20.5 MB  
Reference  -  English Chinese Dictionary -180000 words With Human Voice Offline Dict Free HD 1.1
English-Chinese Dictionary contains 180,000 English words and provides fast search function. Each word has a real-person pronunciation, phonetics, detailed explanation, inflections and usage. English-Chinese Dictionary offers function of...
1024 MB  
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  
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  
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  
NEW DOWNLOADS IN LINUX SOFTWARE, PROGRAMMING
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  
Linux Software  -  SLAX 6.0+
Slax is a modern, portable, small and fast Linux operating system with a modular approach and outstanding design. Despite its small size, Slax provides a wide collection of pre-installed software for daily use, including a well organized graphical...
190 KB  
Linux Software  -  GTK+ 2.5
GTK+, which stands for the GIMP Toolkit, is a library for creating graphical user interfaces for the X Window System. It is designed to be small, efficient, and flexible. GTK+ is written in C with a very object-oriented approach. Language bindings...
60 MB  
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by freedesktop.org, it is used to describe information about an application such as the name and...
327.68 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  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB