public IObservable <Unit> Insert(string key, byte[] data, DateTimeOffset?absoluteExpiration = null) { if (disposed) { return(Observable.Throw <Unit>(new ObjectDisposedException("PersistentBlobCache"))); } if (key == null || data == null) { return(Observable.Throw <Unit>(new ArgumentNullException())); } // NB: Since FetchOrWriteBlobFromDisk is guaranteed to not block, // we never sit on this lock for any real length of time lock (MemoizedRequests) { MemoizedRequests.Invalidate(key); var err = MemoizedRequests.Get(key, data); // If we fail trying to fetch/write the key on disk, we want to // try again instead of replaying the same failure err.LogErrors("Insert").Subscribe( x => CacheIndex[key] = new CacheIndexEntry(Scheduler.Now, absoluteExpiration), ex => Invalidate(key)); return(err.Select(_ => Unit.Default)); } }
public IObservable<Unit> Insert(string key, byte[] data, DateTimeOffset? absoluteExpiration = null) { if (key == null || data == null) { return Observable.Throw<Unit>(new ArgumentNullException()); } // NB: Since FetchOrWriteBlobFromDisk is guaranteed to not block, // we never sit on this lock for any real length of time AsyncSubject<byte[]> err; lock (memoizedRequests) { if (disposed) return Observable.Throw<Unit>(new ObjectDisposedException("PersistentBlobCache")); memoizedRequests.Invalidate(key); err = memoizedRequests.Get(key, data); } // If we fail trying to fetch/write the key on disk, we want to // try again instead of replaying the same failure err.LogErrors("Insert").Subscribe( x => CacheIndex[key] = new CacheIndexEntry(Scheduler.Now, absoluteExpiration), ex => Invalidate(key)); return err.Select(_ => Unit.Default); }
public void Insert(string key, byte[] data, DateTimeOffset? absoluteExpiration = null) { if (disposed) throw new ObjectDisposedException("PersistentBlobCache"); if (key == null || data == null) { throw new ArgumentNullException(); } // NB: Since FetchOrWriteBlobFromDisk is guaranteed to not block, // we never sit on this lock for any real length of time lock (MemoizedRequests) { MemoizedRequests.Invalidate(key); var err = MemoizedRequests.Get(key, data); // If we fail trying to fetch/write the key on disk, we want to // try again instead of replaying the same failure err.LogErrors("Insert").Subscribe( x => CacheIndex[key] = new CacheIndexEntry(Scheduler.Now, absoluteExpiration), ex => Invalidate(key)); } }