CACHING
Para manejar el cache vamos a usar HttpRuntime.Cache["someString"] = variable;
Si al buscar un objeto y este nos devuelve null significa que no existe en el cache.
Este cache se maneja como un diccionario de datos y usandolo de esta manera dejamos que el motor asp.net sea quien administre la duración del mismo.
Si usamos el metodo Add podemos
especificar más opciones para el cache:
public Object Add( string key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback )
Parameters
key
Type: System.String
The cache key used to reference the item.
value
Type: System.Object
The item to be added to the cache.
dependencies
Type: System.Web.Caching.CacheDependency
The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.
absoluteExpiration
Type: System.DateTime
The time at which the added object expires and is removed from the cache. If you are using sliding expiration, the absoluteExpiration parameter must beNoAbsoluteExpiration.
slidingExpiration
Type: System.TimeSpan
The interval between the time the added object was last accessed and the time at which that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If you are using absolute expiration, the slidingExpiration parameter must be NoSlidingExpiration.
priority
Type: System.Web.Caching.CacheItemPriority
The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.
onRemoveCallback
Type: System.Web.Caching.CacheItemRemovedCallback
A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.
Return Value
Type: System.Object
An object that represents the item that was added if the item was previously stored in the cache; otherwise, null.