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.
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.