0

I'm trying to create cache dependency to expire some documents i'm caching using ASP.NET Cache. I came up with this:

public class DocumentCacheDependency : CacheDependency
{
    private readonly IDisposable _Subscription;

    public DocumentCacheDependency(IDocumentStore store, string docId)
    {
        _Subscription = store.Changes().ForDocument(docId).Subscribe(OnDocumentChanged);
        FinishInit();
    }

    private void OnDocumentChanged(DocumentChangeNotification documentChangeNotification)
    {
        NotifyDependencyChanged(this, new EventArgs());
    }

    protected override void DependencyDispose()
    {
        _Subscription.Dispose();
        base.DependencyDispose();
    }
}

Is this a good idea performance wise or should i use the "ForDocumentsStartingWith" / "ForAllDocuments". Or should i create an index. The answer probably depends on the number of documents being cached, so i guess what i'm asking is, is RavenDB optimizing anything for me out of the box when i register hundreds of change listeners, or will the client actually set up hunderds of connections with the db this way.

Tom Allard
  • 61
  • 7

1 Answers1

2

You are probably better off not doing this at all. RavenDB is already going to do caching for you without any cost on your end.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Correct me if I'm wrong but won't the Raven client be querying the server only to receive a "Not Modified" back (unless Aggressive Caching is enabled)? I could see how the custom cache dependency approach might be ideal for certain very performance critical areas right? – John Culviner Oct 16 '13 at 00:00