1

I have a MVC3 application that is serving views stored in a database. I created a VirtualPathProvider and in my GetFile and FileExists methods I go to the database and return the correct thing. So far so good.

Now I want to cache the view I return from GetFile. I understand MVC already does some view caching and we have some control with it via GetCacheDependency method. But do we have more control than this? For example, can we use a custom cache there? In my case, I'm interested in caching the views on local filesystem and do my own cache invalidation.

An easy way would be to do it myself in my GetFile method, but if there's a natural extensibility point for this in MVC I would rather use it instead.

Thanks

Pedro
  • 1,134
  • 11
  • 26

2 Answers2

1

I was looking at something, noticed your question, has not been answered. You would need to override GetFileHash() along with GetCacheDependency(). Then you would need to implement your own CacheDependency to invalidate the ASP.NET Cache.

Sapan Diwakar
  • 10,480
  • 6
  • 33
  • 43
parsh
  • 746
  • 1
  • 10
  • 23
  • You are right parsh, I found that after posting the question and forgot to update it. Although I was under the impression that you could do it by overriding *either* GetFileHash or GetCacheDependency. We did it just with GetCacheDependency. – Pedro Aug 16 '12 at 16:29
0

Either use OutputCacheAttribute

http://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute.aspx

or try deriving from it.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
  • I don't think that's the same thing. AFAIK, output cache will cache the result of the rendered view. View cache will cache the raw view contents prior to rendering. – Pedro Mar 29 '12 at 20:48