I have an application in C# (FrameWork 4.0) running on IIS6.
I'd like to have cached data data (class at foot) permanently, but an event or something similar removes this cached data, in a short time (15-25 mins).
I configure the IIS only with this option: Recycle worker processes (in minutes) 1740.
Any ideas to preserve the data cached? Is the filetime of a static variable is the same as the application lifetime?
public class CacheUsers
{
static object objlock;
private static List<Users> usersList { get; set; }
private static DateTime lastUpdate;
public CacheUsers()
{
if (objlock == null)
{
objlock = new object();
}
lock (objlock)
{
if (usersList == null || usersList.Count.Equals(0) || (lastUpdate < DateTime.Now.AddHours(-24)))
{
UpdateUserList();
}
}
}
public static List<Users> ListaCacheada
{
get
{
if (usersList == null || usersList.Count.Equals(0) || (lastUpdate < DateTime.Now.AddHours(-24)))
{
UpdateUserList();
}
return usersList;
}
}
/// <summary>
/// Refresh the user list
/// </summary>
private static void UpdateUserList()
{
usersList = GetUsers();
lastUpdate = DateTime.Now;
}
}