0

I am building an MVC web application, and I have a few objects in the cache inserted by the following statement:

HttpContext.Current.Cache.Insert("CacheKey", "CachedValue");

I know that I can add a timeout by using the following when inserting an item to the cache:

HttpContext.Current.Cache.Insert("CacheKey", "CachedValue", null, DateTime.Now.AddMilliseconds(10000), Cache.NoSlidingExpiration);

However, my specific requirements are updating the cache timeout once the items have been inserted in the cache. So basically, I need to add a timeout to an existing item in the cache. How would I go about in doing that?

Any help would be appreciated.

5
  • Fetch the item, add it back in with the timeout? Commented Dec 13, 2013 at 17:02
  • could you give me the code to do that? I can fetch the item by HttpContext.Current.Cache["CacheKey"] but how do I add a timeout to this object? Commented Dec 13, 2013 at 17:05
  • You have the code to add a timeout in your OP? Commented Dec 13, 2013 at 17:10
  • does it update the item in the cache if I do an insert again for the same key? Commented Dec 13, 2013 at 17:29
  • Yes it does, that should have been obvious really Commented Dec 16, 2013 at 9:04

2 Answers 2

1

Bit late to the show, but you could do the following, drop the cache and then re-cache with new data. i.e HttpContext.Current.Cache.Remove(your cache id);

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

0

Ok, I found the answer to my question. If I use the insert method, it updates an existing value if there is an object in the cache with the same key.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.