Sto provando a creare un provider Redis per Strathweb.CacheOutput.WebApi2, ma provo a convertire da un byte [] -> RedisValue - > byte [] restituisce null.StackExchange.Redis trasmette RedisValue al byte [] via "come byte []" restituisce null
Posso impostare manualmente il tipo di oggetto come byte [] invece di var/RedisValue e restituirà correttamente il valore come byte [], ma dopo che è stato impostato come RedisValue non riesce a convertirlo in un byte [].
La sua interfaccia ha l'oggetto Restituisci sempre un oggetto quindi non posso forzare il tipo o utilizzare una chiamata separata senza dover modificare l'interfaccia.
Se provo a fare un result as byte[]
ottengo Cannot convert type 'StackExchange.Redis.RedisValue' to 'byte[]' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
Se provo a fare un (byte[])result
ottengo Cannot cast 'result' (which has an actual type of 'StackExchange.Redis.RedisValue') to 'byte[]'
C'è qualcosa che mi manca o sto andando a incidere in in qualche modo controllando che tipo di dati sta cercando in base alla chiave?
Qui è l'interfaccia:
namespace WebApi.OutputCache.Core.Cache
{
public interface IApiOutputCache
{
void RemoveStartsWith(string key);
T Get<T>(string key) where T : class;
object Get(string key);
void Remove(string key);
bool Contains(string key);
void Add(string key, object o, DateTimeOffset expiration, string dependsOnKey = null);
IEnumerable<string> AllKeys { get; }
}
}
Ed ecco come la sua chiamata:
var val = _webApiCache.Get(cachekey) as byte[];
if (val == null) return;
Modifica: Aggiunta di esempi di API I implementate utilizzando entrambe le ServiceStack.Redis v3 (lavora come atm appena usa object
e StackExchange.Redis che non funziona)
https://github.com/mackayj/WebApi.OutputCache.Redis.ServiceStack
https://github.com/mackayj/WebApi.OutputCache.Redis.StackExchange
Il problema è che l'interfaccia restituisce un oggetto e il codice chiamante sta eseguendo un 'come byte []'. Sto provando a non modificare né l'interfaccia né il codice principale, ma penso che sto solo aggiungendo un nuovo metodo che restituisce il byte [] per ora. Ho modificato il mio post per mostrare il codice di chiamata corretto con 'come byte []' – John