- Specific time: absolute expiration
- May also expire if not accessed for a period of time: sliding expiration
Insert Into cache
[vb]
Cache.Insert("myDataSet", ds, Nothing, DateTime.Now.AddSeconds(30), System.TimeSpan.Zero)
[/vb]
Using Cache:
[vb]
If Cache("myDataSet") Is Nothing Then
MyDataSet()
‘DataSet from database
Else
ds = CType(Cache("myDataSet"), DataSet)
‘ DataSet from cache.
End If
[/vb]
Clear Cache:
[vb]
Cache.Remove("myDataSet")
[/vb]
Clear ALL Cache vars:
[vb]
Dim enumerator As IDictionaryEnumerator = HttpContext.Current.Cache.GetEnumerator()
While enumerator.MoveNext()
HttpContext.Current.Cache.Remove(enumerator.Key)
End While
[/vb]
Note that, this technique is not efficient for pages with OutputCache type. for clearing this type cached memory, you should use below code line.
[vb]
HttpRuntime.Close()
[/vb]
Home