Permalink
Browse files

Adding expiration for the document cache, would avoid situation where…

… we have a lot of documents in memory that we no longer reference
  • Loading branch information...
1 parent 0a2c21a commit fe011d18af664aa5c1c55e9f1c9d8d8bf625312e @ayende ayende committed Aug 3, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 Raven.Database/Impl/DocumentCacher.cs
View
10 Raven.Database/Impl/DocumentCacher.cs
@@ -10,8 +10,8 @@ namespace Raven.Database.Impl
public class DocumentCacher : IDocumentCacher
{
private readonly MemoryCache cachedSerializedDocuments;
+
[ThreadStatic]
-
private static bool skipSettingDocumentInCache;
public DocumentCacher(InMemoryRavenConfiguration configuration)
@@ -52,11 +52,15 @@ public void SetCachedDocument(string key, Guid etag, RavenJObject doc, RavenJObj
documentClone.EnsureSnapshot();
var metadataClone = ((RavenJObject)metadata.CloneToken());
metadataClone.EnsureSnapshot();
- cachedSerializedDocuments["Doc/" + key + "/" + etag] = new CachedDocument
+ cachedSerializedDocuments.Set("Doc/" + key + "/" + etag, new CachedDocument
{
Document = documentClone,
Metadata = metadataClone
- };
+ }, new CacheItemPolicy
+ {
+ SlidingExpiration = TimeSpan.FromMinutes(5),
+ });
+
}
public void RemoveCachedDocument(string key, Guid etag)

0 comments on commit fe011d1

Please sign in to comment.