HttpRuntime.Cache - Get CreationTime of Entry

306 Views Asked by At

I have a little CMS which is working with Razor Views which get rendered from a database. Everything is working fine until you change one of the pages.

As the page is assigned to a virtual path, MVC or the RazorViewEngine will cache the view, which makes total sense.

How ever, if someone makes a change i would like to clear the cache for this particular view. Also i would like to clear the cache when before rendering the page. So my idea was to add a "Updated" DateTime information to my View in the database (this field is there anyway as it is one of our standard fields in our tables) and then compare this Date with the CreateTime of the Entry in HttpRuntime.Cache. I can see that there is a CreationTime with VisualStudio but I am not that experienced with Reflection to get to this value.

Also, as I have heard, Reflection isn't very fast and if I have to do it everytime a page gets rendered it would slow down the page.

So my question, can 1. someone help me to get the CreationTime from a HttpRuntime.Cache entry with Reflection or does 2. someone know a better way?

1

There are 1 best solutions below

0
On BEST ANSWER

I was in the wrong place of the MVC Framework, what i was after is the Cache of the VirtualPathProvider, I have found the methods which I have to overwrite. For the ones who face the same problem.

  • GetCacheDependency
  • GetFileHash