Re: Time/size bounded cache?

2011-02-06 Thread Saul Hazledine
On Feb 6, 12:32 pm, Eugen Dück eu...@dueck.org wrote:
 A while back the discussion on the bounded memoize thread in this
 forum lead to Meikel writing up a nice summary of how to do caching,
 providing a pluggable strategy: lru, ttl, fifo, etc. Meikel's writeup
 can be found athttp://kotka.de/blog/2010/03/memoize_done_right.html

 It presents a bunch of different implementations, detailing whats good/
 bad about each of them.

If you need to move function calls out of the cache there is cache-dot-
clj which consists of minor changes to memoize done right:

https://github.com/alienscience/cache-dot-clj

Saul

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Time/size bounded cache?

2011-02-06 Thread Seth
do you really need that? How about an infinite lazy sequence?
(defn infinite [arg]
  (lazy-seq
   (Thread/sleep 2000) ;;simulate 2 second retrieval time
   (concat (for [i (range 0 arg)]
 i) (infinite arg

(def a (infinite 3))
(first a) ;;= sleep 2 seconds, return 0
(take 3 (filter #(= % 2)  a)) ;;wait a bit and return 3 twos

(loop [i 0 a (infinite 3)] ;;wait a bit, process 3 twos, and return
done
  (cond
   (= i 3) done
   (= (first a) 2) (recur (+ i 1) (rest a))
   true (recur i (rest a

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Time/size bounded cache?

2011-02-06 Thread Fogus
 A while back the discussion on the bounded memoize

A truly classic thread, immortalized in JoC and at 
https://github.com/fogus/anamnesis

:-)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Time/size bounded cache?

2011-02-06 Thread Bill James
On Feb 6, 2:08 pm, Seth wbu...@gmail.com wrote:

 (filter #(= % 2)  a)

Another way:

(filter #{2}  a)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Time/size bounded cache?

2010-12-31 Thread Peter Schuller
 The problem is that seen will grow without bounds.
 Is there a built in way to have some sort of LRU cache or should I use
 external libraries (like plru)?

I wrote a persistent LRU cache:

   https://github.com/scode/plru

It's not going to be as memory efficient as a LInkedArrayList, but if
it matters to you do have it be persistent/immutable...

-- 
/ Peter Schuller

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Time/size bounded cache?

2010-12-31 Thread Miki


I wrote a persistent LRU cache:

https://github.com/scode/plru

 Yup, I've looked at it (mentioned in the original post). I might end up 
using it, thanks.
 

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Time/size bounded cache?

2010-12-30 Thread Miki
Hello,

I'm wring a service that polls RSS feeds (using feedme). And I'd like to act 
only on the new entries in each feed.
So far I have something like:

(defn get-new-entries [seen]
  (let [seen? (complement seen)]
(filter #(seen? (:id %)) (get-entries

(defn poll [sleep-time]
  (loop [seen #{}]
(let [entries (get-new-entries seen)]
  (doall (map process-entry entries))
  (println )
  (Thread/sleep sleep-time)
  (recur (union seen (set (map :id entries)))

(Full demo code at https://gist.github.com/760094)

The problem is that seen will grow without bounds.
Is there a built in way to have some sort of LRU cache or should I use 
external libraries (like plru)?

Thanks,
--
Miki

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Time/size bounded cache?

2010-12-30 Thread Chas Emerick
Java's LinkedHashMap provides the hook necessary to implement a simple LRU 
cache.  Here's some code where we use LHM in as an LRU cache, in service of 
providing a variation on the memoization concept:

https://gist.github.com/747395

Whether what's there is sufficient for your needs is another story. :-)

- Chas

On Dec 30, 2010, at 1:35 PM, Miki wrote:

 Hello,
 
 I'm wring a service that polls RSS feeds (using feedme). And I'd like to act 
 only on the new entries in each feed.
 So far I have something like:
 
 (defn get-new-entries [seen]
   (let [seen? (complement seen)]
 (filter #(seen? (:id %)) (get-entries
 
 (defn poll [sleep-time]
   (loop [seen #{}]
 (let [entries (get-new-entries seen)]
   (doall (map process-entry entries))
   (println )
   (Thread/sleep sleep-time)
   (recur (union seen (set (map :id entries)))
 
 (Full demo code at https://gist.github.com/760094)
 
 The problem is that seen will grow without bounds.
 Is there a built in way to have some sort of LRU cache or should I use 
 external libraries (like plru)?
 
 Thanks,
 --
 Miki
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Time/size bounded cache?

2010-12-30 Thread Luke VanderHart
I've been working on a simple Clojure library for bounded caching and
memoization. It's not quite ready for prime-time, but the simple case
that you need is usable.

I'll throw it up on github when I get home tonight and post the URL
here.

On Dec 30, 1:35 pm, Miki miki.teb...@gmail.com wrote:
 Hello,

 I'm wring a service that polls RSS feeds (using feedme). And I'd like to act
 only on the new entries in each feed.
 So far I have something like:

 (defn get-new-entries [seen]
   (let [seen? (complement seen)]
     (filter #(seen? (:id %)) (get-entries

 (defn poll [sleep-time]
   (loop [seen #{}]
     (let [entries (get-new-entries seen)]
       (doall (map process-entry entries))
       (println )
       (Thread/sleep sleep-time)
       (recur (union seen (set (map :id entries)))

 (Full demo code athttps://gist.github.com/760094)

 The problem is that seen will grow without bounds.
 Is there a built in way to have some sort of LRU cache or should I use
 external libraries (like plru)?

 Thanks,
 --
 Miki

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en