I have a .net application variable cached. What I want to do it get the cache to recycle the variable every half hour on the hour, 1, 1.30, 2, 2.30 etc. I have the onRemoveCallback function set and everything works, my real question is what is the best way to generate the correct absoluteExpiration value?
DateTime time_to_expire = DateTime.Now;
if (time_to_expire.Minute < 29)
{
time_to_expire = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 30, 0);
}
else
{
time_to_expire = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour + 1, 0, 0);
}
The reason I test the time_to_expire value to 29 is that I am worried about boundary cases and I don’t want the variable to ‘go blank’ for a half hour period! Ideas on how to do this better?
Thanks
Don’t know that it is any “better” but I would be inclined to do something like this: