File cache for images

Discussion in 'Python' started by =?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLR, Sep 20, 2004.

  1. 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.
    =?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLR, Sep 20, 2004
    #1
    1. Advertising

  2. "" 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>
    Fredrik Lundh, Sep 20, 2004
    #2
    1. Advertising

  3. > 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.
    =?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLR, Sep 20, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Nokes

    Cache::Cache Stale Segments

    Jeff Nokes, Sep 30, 2003, in forum: Perl
    Replies:
    0
    Views:
    558
    Jeff Nokes
    Sep 30, 2003
  2. DesignerX

    Page.Cache vs HttpContext.Current.Cache

    DesignerX, Jan 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    8,227
    vMike
    Jan 20, 2004
  3. =?Utf-8?B?b25l?=
    Replies:
    1
    Views:
    5,272
    Karl Seguin [MVP]
    Mar 8, 2006
  4. Sergey via DotNetMonster.com

    ASP.NET Cache vs Window System Cache

    Sergey via DotNetMonster.com, Nov 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    464
    Sergey via DotNetMonster.com
    Nov 15, 2006
  5. wardemon

    Cache Images vs Static Images

    wardemon, Jun 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    647
    bruce barker
    Jun 14, 2007
Loading...

Share This Page