title: Membase server And Enyim -- Integrating LINQ and/or Collections
body: <p>I just installed membase and the enyim client for .NET, and came across an article that mentions this technique for integrating linq:</p>
  
  <pre><code>    public static IEnumerable&lt;T&gt; CachedQuery&lt;T&gt;
          (this IQueryable&lt;T&gt; query, MembaseClient cache, string key) where T : class
      {
          object result; 
          if (cache.TryGet(key, out result))
          {
              return (IEnumerable&lt;T&gt;)result;
          }
          else
          {
              IEnumerable&lt;T&gt; items = query.ToList();
              cache.Store(StoreMode.Set, key, items);
              return items;
          }
      }
  </code></pre>
  
  <p>It will check if the required data is in cache first, and if not cache it then return it. </p>
  
  <p>Currently I am using a <code> Dictionary&lt;'String, List'> </code> in my application and want to replace this with a membase/memcached type approach. </p>
  
  <p>What about a similar pattern for adding items to a List&lt;'T'> or using Linq operators on a cached list? It seems to me that it could be a bad idea to store an entire List&lt;'T'> in cache under a single key and have to retrieve it, add to it, and then re-set it each time you want to add an element. Or is this an acceptable practice?</p>
  
  <pre><code>    public bool Add(T item)
      {
          object list;
          if (cache.TryGet(this.Key, out list))
          {
              var _list = list as List&lt;T&gt;;
              _list.Add(item);
              return cache.Store(StoreMode.Set, this.Key, _list); 
          }
          else
          {
              var _list = new List&lt;T&gt;(new T[] { item });
              return cache.Store(StoreMode.Set, this.Key, _list); 
          }
      }
  </code></pre>
  
  <p>How are collections usually handled in a caching situation like this? Are hashing algorithms usually used instead, or some sort of key-prefixing system to identify 'Lists' of type T within the key-value store of the cache?</p>