File cache for images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Дамјан Георгиевски

    #1

    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:

    getmodifiedimag e(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.
  • Fredrik Lundh

    #2
    Re: File cache for images

    "me@here.there. nowhere" wrote:[color=blue]
    > I'm looking for a way to cache some modified images as files (in a python
    > program ofcourse). The scenario would look like this:
    >
    > getmodifiedimag e(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 :)[/color]

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

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

    </F>



    Comment

    • Дамјан Георгиевски

      #3
      Re: File cache for images

      > I'm looking for a way to cache some modified images as files (in a python[color=blue]
      > program ofcourse). The scenario would look like this:
      >
      > getmodifiedimag e(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 :)[/color]

      I've read Fredrik Lundh answer on Google Groups, since it didn't appear on
      my news server.
      [color=blue][color=green]
      >> I'm not sure what "modify filename" means[/color][/color]

      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.

      Comment

      Working...