Ho una classe che assomiglia a questo:Come utilizzare System.Web.Caching in asp.net?
using System.Collections.Generic;
using System.Web.Caching;
public static class MyCache
{
private static string cacheKey = "mykey";
public static Dictionary<string, bool> GetCacheValue(bool bypassCache)
{
var settings = Cache[cacheKey] as Dictionary<string, bool>; // error on this line
// ...etc...
return settings
}
}
il problema che sto avendo è che questa abitudine di compilazione. Il compilatore dice che lo Cache
non può essere usato nel modo in cui lo sto facendo. Ecco il messaggio:
'System.Web.Caching.Cache' is a 'type' but is used like a 'variable'
Questo mi lascia perplesso. Ho cercato su google l'API di ASP.NET Cache e ho trovato molti esempi di Cache
utilizzati in questo modo. Ecco uno di quegli esempi:
// http://www.4guysfromrolla.com/articles/100902-1.aspx
value = Cache("key")
- or -
value = Cache.Get("key")
Quando provo utilizza Cache.Get()
ottengo un altro errore dicendo che non è un metodo statico.
Evidentemente ho bisogno di inizializzare un'istanza di Cache
. È questo il modo corretto di usare questa API? Una domanda di follow-up è, le informazioni memorizzate nella cache persistono tra le istanze?
Grazie per il vostro aiuto.
Usa 'HttpRuntime.Cache' per arrivare a' esempio cache'. – MarcinJuraszek