0

In my ASP.NET web site I persist objects retrieved from DB for some time and make sure that the only single instance of object is created per DB record.

I also use [InstanceCache] to cache calculated value for one of business objects, object is kept in cache for the duration of user session.

Today, though, I came across the use-case when I would like to invalidate cached value.

How can I do this for properties that are cached using [InstanceCache]?

Please advise.

Thank you.

Budda
  • 18,015
  • 33
  • 124
  • 206
  • did you try the `ClearCache` methods as I suggested? Did they work for you? Some feedback would be appreciated. – Alex May 19 '15 at 20:44

1 Answers1

0

I think you may be able to do that by using one of the ClearCache static methods of the CacheAspect class, that allow clearing the cache at different levels of granularity:

public static void ClearCache(MethodInfo methodInfo);
public static void ClearCache(Type declaringType, string methodName, params Type[] types);
public static void ClearCache(Type declaringType, string methodName, Type[] types, object[] values);
public static void ClearCache(Type declaringType);
public static void ClearCache();

If you want to clear the cache only for the specific [InstanceCache] property, you will need to get its MethodInfo (for the "get" method of the property I think) using reflection and pass that along to the first variant.

This seems to work for regular [Cache] attribute annotations, so if clearing the cache for [InstanceCache] items is at all supported, this would be the route to go.

Alex
  • 13,024
  • 33
  • 62
  • So far I decided to delete the instance itself... which in turn causes new cache value to be calculated, so I don't need to invalidate cache NOW. But idea to call static method ClearCache looks... too complex. Will give it a try to better understand it anyway. Thanks! – Budda May 20 '15 at 00:52