Что-то вроде этого возможно?
using System;
using System.Collections.Generic;
using System.Web;
public class MyListCache
{
private List<object> _MyList = null;
public List<object> MyList {
get {
if (_MyList == null) {
_MyList = (HttpContext.Current.Cache["MyList"] as List<object>);
if (_MyList == null) {
_MyList = new List<object>();
HttpContext.Current.Cache.Insert("MyList", _MyList);
}
}
return _MyList;
}
set {
HttpContext.Current.Cache.Insert("MyList", _MyList);
}
}
public void ClearList() {
HttpContext.Current.Cache.Remove("MyList");
}
}
Что касается того, как использовать .....
// Get an instance
var listCache = new MyListCache();
// Add something
listCache.MyList.Add(someObject);
// Enumerate
foreach(var o in listCache.MyList) {
Console.WriteLine(o.ToString());
}
// Blow it away
listCache.ClearList();