﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Damien Guard commented on Implementing LRU cache</title><description>If multiple threads call in on a cache miss at the same time you'll end up with a cache entry that has a usage of 1.

[)amien</description><link>http://ayende.com/158433/implementing-lru-cache#comment17</link><guid>http://ayende.com/158433/implementing-lru-cache#comment17</guid><pubDate>Sat, 06 Oct 2012 17:11:56 GMT</pubDate></item><item><title>Patrick Huizinga commented on Implementing LRU cache</title><description>One small nitpick: this doesn't look like a LRU (Least Recently Used) cache, but more like a (LFU) Least Frequently Used cache.</description><link>http://ayende.com/158433/implementing-lru-cache#comment16</link><guid>http://ayende.com/158433/implementing-lru-cache#comment16</guid><pubDate>Tue, 18 Sep 2012 13:45:23 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Davh,
The only requests that require admin privileges are things like "create new db, back a db, delete a db".
Those tend to be fairly rare :-)</description><link>http://ayende.com/158433/implementing-lru-cache#comment15</link><guid>http://ayende.com/158433/implementing-lru-cache#comment15</guid><pubDate>Fri, 14 Sep 2012 07:45:18 GMT</pubDate></item><item><title>davh commented on Implementing LRU cache</title><description>You never know when someone chose to make all their users admin and let them access the db :) e.g. some test server in a software development company where they all have admin access to it.</description><link>http://ayende.com/158433/implementing-lru-cache#comment14</link><guid>http://ayende.com/158433/implementing-lru-cache#comment14</guid><pubDate>Fri, 14 Sep 2012 07:43:11 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Dennis,
I see, good point. 
I fixed both issues, but I don't think either would have been a problem.
This is a LRU for admins, the number of expected admins is low, and the number of requests requiring them is even lower :-)</description><link>http://ayende.com/158433/implementing-lru-cache#comment13</link><guid>http://ayende.com/158433/implementing-lru-cache#comment13</guid><pubDate>Fri, 14 Sep 2012 07:28:43 GMT</pubDate></item><item><title>Dennis commented on Implementing LRU cache</title><description>The most annoying part about LRU caches is that they are prune to cache trashing. If you have more users (in this case) than the max cache size, a LRU is worse than not having a cache.
So it would therefore be very useful to get a log entry every time the max size is exceed. Then it is very visible for someone complaining about slow logins if they are in the situation where the cache is not working.
And btw, you forgot to prune expired entries before the Least recently used.</description><link>http://ayende.com/158433/implementing-lru-cache#comment12</link><guid>http://ayende.com/158433/implementing-lru-cache#comment12</guid><pubDate>Fri, 14 Sep 2012 07:22:18 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Davh,
Can you explain a bit more about what you mean here?</description><link>http://ayende.com/158433/implementing-lru-cache#comment11</link><guid>http://ayende.com/158433/implementing-lru-cache#comment11</guid><pubDate>Fri, 14 Sep 2012 07:15:44 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Rafal,
We actually have several. The difference is that each have different semantics.
From Admin, we take into account duration, for caching execution plans, we take into account memory and time.
We use specialized versions, because we don't have the need for a uber generic one.</description><link>http://ayende.com/158433/implementing-lru-cache#comment10</link><guid>http://ayende.com/158433/implementing-lru-cache#comment10</guid><pubDate>Fri, 14 Sep 2012 07:14:57 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Tobi,
Excellent commentary, I've modified the actual cache to use Lazy to avoid this issue.</description><link>http://ayende.com/158433/implementing-lru-cache#comment9</link><guid>http://ayende.com/158433/implementing-lru-cache#comment9</guid><pubDate>Fri, 14 Sep 2012 07:08:32 GMT</pubDate></item><item><title>Ayende Rahien commented on Implementing LRU cache</title><description>Steve,
That is a ConcurretnDictionary there, it won't throw under this scenario.</description><link>http://ayende.com/158433/implementing-lru-cache#comment8</link><guid>http://ayende.com/158433/implementing-lru-cache#comment8</guid><pubDate>Fri, 14 Sep 2012 07:01:18 GMT</pubDate></item><item><title>davh commented on Implementing LRU cache</title><description>You forgot to add a log entry when it does clear the cache, so that it is possible to see when cache trashing occurs.</description><link>http://ayende.com/158433/implementing-lru-cache#comment7</link><guid>http://ayende.com/158433/implementing-lru-cache#comment7</guid><pubDate>Fri, 14 Sep 2012 06:45:58 GMT</pubDate></item><item><title>Steve commented on Implementing LRU cache</title><description>@tobi, If he doesn't expect to even reach MaxCacheSize (25) then I see no problem with this implementation.

But do you have the name of the pattern that could handle the load you are describing?</description><link>http://ayende.com/158433/implementing-lru-cache#comment6</link><guid>http://ayende.com/158433/implementing-lru-cache#comment6</guid><pubDate>Thu, 13 Sep 2012 20:58:29 GMT</pubDate></item><item><title>Steve commented on Implementing LRU cache</title><description>ConcurrentDictionary does not work with a "version" like the generic collections and doesn't throw on modified collections while enumerating, it seems to handle most cases like expected :)

            var dict = new ConcurrentDictionary&lt;string, string&gt;();
            for (var i = 0; i &lt; 5; i++)
                dict.TryAdd("Test" + i, "");

            foreach (var entry in dict)
            {
                string value;
                dict.TryRemove(entry.Key, out value);
            }

Leaves you with an empty dict.</description><link>http://ayende.com/158433/implementing-lru-cache#comment5</link><guid>http://ayende.com/158433/implementing-lru-cache#comment5</guid><pubDate>Thu, 13 Sep 2012 20:55:59 GMT</pubDate></item><item><title>tobi commented on Implementing LRU cache</title><description>A simple fix is not to cache a T but a Lazy[T] at the highest mode of synchronization.</description><link>http://ayende.com/158433/implementing-lru-cache#comment4</link><guid>http://ayende.com/158433/implementing-lru-cache#comment4</guid><pubDate>Thu, 13 Sep 2012 20:07:00 GMT</pubDate></item><item><title>Rafal commented on Implementing LRU cache</title><description>Nice implementation, but how is it possible that there was no general-purpose LRU cache in Raven?
And watch out for the API:
Some time ago I have been tasked with implementing similar, windows-based security and had quite serious problems with accessing user information through UserPrincipal API (there were two mutually trusted domains where users could belong to groups in both of them - in such case the MS API sometimes kept throwing undocumented errors at me). 
And this made me wonder if we could give all that work to Windows file system - by checking user permissions to designated files representing various application rights.</description><link>http://ayende.com/158433/implementing-lru-cache#comment3</link><guid>http://ayende.com/158433/implementing-lru-cache#comment3</guid><pubDate>Thu, 13 Sep 2012 20:05:23 GMT</pubDate></item><item><title>tobi commented on Implementing LRU cache</title><description>This cache suffers from cache stampeding. At 1000k requests per seconds and 2s to produce a cache value this will *overwhelm* the poor AD server. It will need to handle 2k requests in 2sec suddenly when the cache item expires.

I hate caches which use the CAS pattern (get, produce, try-insert). This only goes well if there is little load on the individual cache item.
</description><link>http://ayende.com/158433/implementing-lru-cache#comment2</link><guid>http://ayende.com/158433/implementing-lru-cache#comment2</guid><pubDate>Thu, 13 Sep 2012 20:03:40 GMT</pubDate></item><item><title>Steve commented on Implementing LRU cache</title><description>Doesn't the foreach throw an exception if you modify the cache inside the loop?</description><link>http://ayende.com/158433/implementing-lru-cache#comment1</link><guid>http://ayende.com/158433/implementing-lru-cache#comment1</guid><pubDate>Thu, 13 Sep 2012 19:57:39 GMT</pubDate></item></channel></rss>