Caching until 23:59 o'clock...

M

mesut

Hi colleagues,

I have a small issue. I don't know how to solve it. I'm caching a
property value : True or False. I do this manually and it works. But I
would like to remove the cache if the the time is 23:59 o'clock. How
can I automatically release the cache at 23:59 or 23:00 o'clock? Look
at line 7. I don't know what the syntax is. Can someone help me?
Idea is if the time raises 23:59:00 o'clock the cache need to be
removed automatically. I only want to cache until the end of the day.
The other day it should be dissapeared.

thanks in advance for your help,
mesut

1 Public Property Frozen() As Boolean
2 GET
3 ' ... END GET
4 Set(ByVal value As Boolean)
5 If value Then
6 Cache(FrozenCacheKey) = True
7 Cache.Insert(FrozenCacheKey, value, Nothing,
DateTime(("23:59:00")))
8 Else
9 If Not Cache(FrozenCacheKey) Is Nothing Then
10 Cache.Remove(FrozenCacheKey)
11 End If
12 End If
13 End Set
End Property
 
A

Alexey Smirnov

Hi colleagues,

I have a small issue. I don't know how to solve it. I'm caching a
property value : True or False. I do this manually and it works. But I
would like to remove the cache if the the time is 23:59 o'clock. How
can I automatically release the cache at 23:59 or 23:00 o'clock? Look
at line 7. I don't know what the syntax is. Can someone help me?
Idea is if the time raises 23:59:00 o'clock the cache need to be
removed automatically. I only want to cache until the end of the day.
The other day it should be dissapeared.

thanks in advance for your help,
mesut

1 Public Property Frozen() As Boolean
2 GET
3 ' ... END GET
4 Set(ByVal value As Boolean)
5 If value Then
6 Cache(FrozenCacheKey) = True
7 Cache.Insert(FrozenCacheKey, value, Nothing,
DateTime(("23:59:00")))
8 Else
9 If Not Cache(FrozenCacheKey) Is Nothing Then
10 Cache.Remove(FrozenCacheKey)
11 End If
12 End If
13 End Set
End Property

I think you can try

DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59")
 
M

mesut

Hi Alexy,

thanks for your reply...

When I try :
Cache.Insert(FrozenCacheKey, value, Nothing,
DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59"))
I get error: -> Overload resolution faield because no accesible
'Insert' acepts this number of arguments.

Cache(FrozenCacheKey) = True with this code line I set the value to
True.
But I would like to cache until 23:59:59 o'clock the same day. Is my
code correct above? I mean I'm using the cache.insert function. Is
this correct?

thanks for your help,

mesut
 
H

Hans Kesting

Hi Alexy,
thanks for your reply...

When I try :
Cache.Insert(FrozenCacheKey, value, Nothing,
DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59"))
I get error: -> Overload resolution faield because no accesible
'Insert' acepts this number of arguments.
Cache(FrozenCacheKey) = True with this code line I set the value to
True.
But I would like to cache until 23:59:59 o'clock the same day. Is my
code correct above? I mean I'm using the cache.insert function. Is
this correct?
thanks for your help,

mesut

Instead of going through ToString() and Parse(), you could use
DateTime.Today.Add(new TimeSpan(23,59,59))

The Cache.Insert method requires another parameter, use
System.Web.Caching.Cache.NoSlidingExpiration

(it's used to set a "sliding expiration": expire when it hasn't been
accessed within this time. NoSlidingExpiration disables this)

Hans Kestin
 
A

Alexey Smirnov

I get error: -> Overload resolution faield because no accesible
'Insert' acepts this number of arguments.

That's true - http://msdn2.microsoft.com/en-us/library/system.web.caching.cache.insert.aspx

I guess you wanted to use

Cache.Insert Method (String, Object, CacheDependency, DateTime,
TimeSpan)
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx

which required 5 arguments

and where you've missed a slidingExpiration (the interval between the
time the inserted object is last accessed and the time at which that
object expires)

In your case you can use the Cache.NoSlidingExpiration value
 
M

mesut

Super thanks Alexey and Hans,

Both works.... thaks you very much for your help again,

cheers, mesut :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top