Fork me on GitHub
#beginners
<
2015-09-24
>
clojuregeek20:09:12

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

upgradingdave20:09:04

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 https://github.com/clojure/core.cache/wiki/Extending). 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?

clojuregeek20:09:25

when i try to use that value i have an error, i print it in a log and it looks like INFO: Using format clojure.core$fnil$fn__5496@a8995f2

upgradingdave20:09:58

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

venantius20:09:03

@clojuregeek: your parens aren’t aligned

venantius20:09:27

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

clojuregeek20:09:46

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

clojuregeek20:09:41

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

rauh20:09:16

@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?

upgradingdave20:09:18

@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

upgradingdave20:09:55

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

rauh20:09:06

@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

upgradingdave20:09:10

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

rauh20:09:50

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

upgradingdave20:09:38

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

rauh20:09:29

@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

rauh20:09:59

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

rauh20:09:36

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

upgradingdave20:09:11

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!