473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File cache for images

I'm looking for a way to cache some modified images as files (in a python
program ofcourse). The scenario would look like this:

getmodifiedimage(filename):
is it in cache?
is the cache up to date (not older than file)
if not, modify filename and store in cache (keyed by filename +
modification)
return modified image
I'm looking for prior-art before inventing it myself :)

--
дамјан

If Bill Gates had a dime for every time a Windows box crashed...
...Oh, wait a minute, he already does.
Jul 18 '05 #1
2 2584
"me@here.there.nowhere" wrote:
I'm looking for a way to cache some modified images as files (in a python
program ofcourse). The scenario would look like this:

getmodifiedimage(filename):
is it in cache?
is the cache up to date (not older than file)
if not, modify filename and store in cache
(keyed by filename + modification)
return modified image

I'm looking for prior-art before inventing it myself :)


I'm not sure what "modify filename" means, but a straightforward
solution is not that much longer than your pseudocode:

def getmodifiedimage(filename, cache={}):
try:
image, mtime = cache[filename]
if mtime < os.path.getmtime(filename):
raise KeyError
except KeyError:
image = open(filename, "rb").read() # or something
cache[filename] = image, os.path.getmtime(filename)
return image

</F>

Jul 18 '05 #2
> I'm looking for a way to cache some modified images as files (in a python
program ofcourse). The scenario would look like this:

getmodifiedimage(filename):
is it in cache?
is the cache up to date (not older than file)
if not, modify filename and store in cache (keyed by filename +
modification)
return modified image
I'm looking for prior-art before inventing it myself :)


I've read Fredrik Lundh answer on Google Groups, since it didn't appear on
my news server.
I'm not sure what "modify filename" means


I dont want to cache file in memory (a dict in your ex.), access to the file
is cheap. I want to modify the image (say create a thumbnail, or watermark
it) and cache the thumbnail in a file.

.... but anyway it should be easy to implement really... It's just I've had a
fealing I miss something... well maybe I miss the implementation of
removing least recently used files in the cache, when the cache becomes
full (as configured).

--
дамјан

Press every key to continue.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Bill H | last post by:
I have a routine that displays 60 items (with thumbnails) per page. You can click any item and displays a new page with item details. When the user back pages it runs the query again to display all...
16
by: Donjuan | last post by:
Hi all I have trouble with tracking whether my image file is loaded. i use DHTML to change my image. HERE is the code: <img name="someimage" src="1.jpg"...
9
by: Ivan Demkovitch | last post by:
Hi! I would like to know if I can save File on Server using server-side code? For example, I like to create thumbnail images and populate specific directory. Do I need specific permissions...
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
2
by: thehuby | last post by:
I am building a CMS and as part of it a user can upload an image. Once uploaded I am displaying the image. If the user then decides they want to replace the image with another I get a caching...
3
by: shotokan99 | last post by:
hi, shall we say you want to creae a banner, a button, and other images for your site. some create images on the fly through php using gd library. is this more advisable or more efficient...
4
by: MattB | last post by:
Hi. I have an asp.net 1.1 application that I need to retrieve a jpeg image from a database and write that to the local (not client's) file system. What I'm doing is a club login page, and each...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
3
by: rajkumarpb | last post by:
Hi friends, I am new to this forum...But not for programming...I want a Print CSS File to be added in my page..OK.... Here is the page and i want you friends to help me create the CSS File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.