Fork me on GitHub

trying to get the value of params[format] else return "yaml" (fnil (:format (get-in req [:params])) "yaml")


hey clojurians, I have a program that generates thumbnail image files and I’d like to have it automatically manage the thumbnail files inside a cache, I was thinking of trying to create a new core.cache type (like described here The new cache type could create files on cache misses, and delete files on evictions. Does that sound like a good way to go about it? Any other ideas on how to implement a cache of thumbnail files?


when i try to use that value i have an error, i print it in a log and it looks like INFO: Using format [email protected]


@clojuregeek, I think get-in accepts a third param “not-found” so maybe something like this? (get-in req [:params :format] "yaml”)


@clojuregeek: your parens aren’t aligned


by which I mean I think “yaml” should immediately follow [:params], surely?


yeah i cut it out of a bigger sexp ... i'll try the get -in


that works @upgradingdave .. thanks! simple_smile i guess i was making it bigger problem then it was simple_smile simple_smile


@upgradingdave: Have you tried letting the OS do the file system caching for you? Are you sure you need to hold the image in JVM memory?


@rauh, no I’d rather not hold the files in memory. I was thinking maybe have a simple lru cache that looks something like this {“path-to-file1” true, “path-tofile2” true} and then customize the evict method so that the files actually get removed from disk


I hadn’t really looked into os doing the caching. Ideally I think it’d be cool if it were all contained in the jvm though


@upgradingdave: Now I understand what you're trying to do. In that case I'd just clean them up (like a garbage collector) after a while. In that case, yes I think the LRU cache of core.cache is not a bad idea


it’s just a toy project I’m working on so like to keep it as simple as possible


If it's a toy project: Just never remove the thumbnails. File space is dirt cheap.


cool, thanks, @rauh, good to know I’m not way off 😉


@upgradingdave: Many file systems also have "atime" (access time) which you could use with a simple bash script to remove files after a few months if you really want to


I always like to keep it simple. I'm sure you do it (more complicated) with clojure too simple_smile


I see man find has an atime modifier. So a one-liner in bash.


definitely an option to just blow away older thumbnails, thanks. I thought this’d be a good chance to dive deeper into core.cache for fun mostly, so I think I’ll run with it and see what I can come up with, thanks again!