Note that there are some explanatory texts on larger screens.

plurals
  1. POCache or MultiMap for day-based cache expiration?
    primarykey
    data
    text
    <p>Context: I'm working on an analytics system for an ordering system. There are about 100,000 orders per day and the analytics need to run for the last N (say, 100) days months. The relevant data fits in memory. After N days, all orders are evicted from the memory cache, with an entire day in the past being evicted. Orders can be created or updated.</p> <ol> <li><p>A traditional approach would use a <code>ConcurrentHashMap&lt;Date, Queue&lt;Order&gt;&gt;</code>. Every day, values for keys representing dates more than N days in the past will be deleted. But, of course, the whole point of using Guava is to avoid this. EDIT: changed <code>Map</code> to <code>ConcurrentHashMap</code>, see the end of the question for rationale.</p></li> <li><p>With Guava collections, a <code>MultiMap &lt;Date, Order&gt;</code> would be simpler. Eviction is similar, implemented explicitly.</p></li> <li><p>While the <code>Cache</code> implementation looks appealing (after all, I am implementing a Cache), I'm not sure about the eviction options. Eviction only happens once a day and its best initiated from outside the cache, I don't want the cache to have to check the age of an order. I'm not even sure if the cache would use a MultiMap, which I think it's a suitable data structure in this case.</p></li> </ol> <p>Thus, my question is: is it possible to use a Cache that uses and exposes the semantics of a MultiMap and allows evictions controlled from outside itself, in particular with the rule I need ("delete all orders older than N days") ?</p> <p>As an important clarification, I'm not interested in a <code>LoadingCache</code> but I do need bulk loads (if the application needs to be restarted, the cache has to be populated, from the database, with the last N days of orders).</p> <p>EDIT: Forgot to mention that the map <em>needs to be concurrent</em>, as orders come in they are evaluated live against the previous orders for the same customer or location etc. </p> <p>EDIT2: Just stumbled over <a href="http://code.google.com/p/guava-libraries/issues/detail?id=135" rel="nofollow">Guava issue 135</a>. It looks like the MultiMap is not concurrent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload