Last night I tried to implement my idea for a ‘LRU File Store’ for Rails fragment caching. The idea was that it would extend the standard FileStore, and just override the read method so that it would ‘touch’ a file if it was read. This would make it easy for a cleanup script to find the oldest cached files, which are more eligible for deletion.

Unfortunately I ran into difficulties, which I thought at the time were due to class loading path issues, but actually turned out to be just because I got the module name wrong for the class I was trying to extend1.

This morning I did some looking around and realised what the issue was. I also found Dominic Mitchell’s TimedFileStore plugin, which was quite instructive.

But after the effort, I discovered I don’t need a special file store anyway – I can use the atime attribute of the files to see when they were last accessed, so I don’t need to go hitting them2.

1 Excuses: I was tired and not thinking well. I keep telling myself I have to avoid the behaviour of guessing what the problem is and then trying to fix that problem, but I slip back into it sometimes.

2 I’m not very clear on how portable atime is to Windows, but my live app will be deployed on Linux so I guess it doesn’t matter.


  1. Loz
    Posted November 1, 2006 at 6:51 am | Permalink

    Filesystems in Linux can be mounted with noatime set, it’s supposed to improve performance (seems reasonable as maintaining atime turns every read into a write). Maybe you If you put the cache on its own filesystem you can get the best of both worlds.

  2. Posted November 1, 2006 at 6:57 am | Permalink

    Ah, thanks for pointing that out, it could have made me even more confused! I’m deploying this to my shared host site, so I can’t really change what filesystem it goes on, but I can do some testing to see how the site behaves.

  3. Marble
    Posted November 2, 2006 at 1:25 am | Permalink

    atime/ctime/mtime usually work with NTFS, but not FAT.
    Mounting with noatime is often done with flash memory drives under linux, because it reduces the amount of writing, which would wear out the flash memory, but I’ve not often seen it done on harddisc filesystems.

  4. Posted November 2, 2006 at 1:41 am | Permalink

    I did a little testing (using IRB), which suggests that atime will work ok for my purposes. I didn’t yet get very far with writing the actual script that uses it though.

Post a Comment

Your email is never published nor shared. Required fields are marked *