本文整理汇总了C#中CacheItem类的典型用法代码示例。如果您正苦于以下问题:C# CacheItem类的具体用法?C# CacheItem怎么用?C# CacheItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheItem类属于命名空间,在下文中一共展示了CacheItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
public Bitmap this[ScannedImage scannedImage]
{
get
{
var newState = scannedImage.GetThumbnailState();
if (cache.ContainsKey(scannedImage))
{
// Cache hit
var item = cache[scannedImage];
if (item.State != newState)
{
// Invalidated
item.Thumbnail.Dispose();
item.Thumbnail = scannedImage.GetThumbnail(userConfigManager.Config.ThumbnailSize);
item.State = newState;
}
return item.Thumbnail;
}
else
{
// Cache miss
var item = new CacheItem
{
Thumbnail = scannedImage.GetThumbnail(userConfigManager.Config.ThumbnailSize),
State = newState
};
return item.Thumbnail;
}
}
}
示例2: ImageListViewCacheManager
/// <summary>
/// Initializes a new instance of the ImageListViewCacheManager class.
/// </summary>
/// <param name="owner">The owner control.</param>
public ImageListViewCacheManager(ImageListView owner)
{
lockObject = new object();
mImageListView = owner;
mCacheMode = CacheMode.OnDemand;
mCacheLimitAsItemCount = 0;
mCacheLimitAsMemory = 20 * 1024 * 1024;
mRetryOnError = owner.RetryOnError;
toCache = new Stack<CacheItem>();
thumbCache = new Dictionary<Guid, CacheItem>();
editCache = new Dictionary<Guid, Image>();
rendererToCache = new Stack<CacheItem>();
rendererGuid = new Guid();
rendererItem = null;
memoryUsed = 0;
memoryUsedByRemoved = 0;
removedItems = new List<Guid>();
mThread = new Thread(new ThreadStart(DoWork));
mThread.IsBackground = true;
stopping = false;
stopped = false;
disposed = false;
mThread.Start();
while (!mThread.IsAlive) ;
}
示例3: StoreOperation
public StoreOperation(StoreMode mode, string key, CacheItem value, uint expires)
: base(key)
{
this.mode = mode;
this.value = value;
this.expires = expires;
}
示例4: CanScavengeInBackground
public void CanScavengeInBackground()
{
CacheItem item1 = new CacheItem("key1", "value1", CacheItemPriority.Low, null);
CacheItem item2 = new CacheItem("key2", "value2", CacheItemPriority.Normal, null);
CacheItem item3 = new CacheItem("key3", "value3", CacheItemPriority.High, null);
AddCacheItem("key1", item1);
AddCacheItem("key2", item2);
AddCacheItem("key3", item3);
TestConfigurationContext context = new TestConfigurationContext();
CachingConfigurationView view = new CachingConfigurationView(context);
view.GetCacheManagerSettings().CacheManagers["test"].MaximumElementsInCacheBeforeScavenging = 2;
view.GetCacheManagerSettings().CacheManagers["test"].NumberToRemoveWhenScavenging = 1;
CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", view);
ScavengerTask scavenger = new ScavengerTask("test", view, scavengingPolicy, this);
BackgroundScheduler scheduler = new BackgroundScheduler(null, scavenger);
scheduler.Start();
Thread.Sleep(500);
scheduler.StartScavenging();
Thread.Sleep(250);
scheduler.Stop();
Thread.Sleep(250);
Assert.AreEqual("key1", scavengedKeys);
}
示例5: CallbackReasonScavengedIsGivenToCallbackMethod
public void CallbackReasonScavengedIsGivenToCallbackMethod()
{
CacheItem emptyCacheItem = new CacheItem("key", null, CacheItemPriority.Low, new MockRefreshAction());
RefreshActionInvoker.InvokeRefreshAction(emptyCacheItem, CacheItemRemovedReason.Scavenged, instrumentationProvider);
Thread.Sleep(100);
Assert.AreEqual(CacheItemRemovedReason.Scavenged, callbackReason);
}
示例6: RemovedValueCanBeNullDuringCallback
public void RemovedValueCanBeNullDuringCallback()
{
CacheItem emptyCacheItem = new CacheItem("key", null, CacheItemPriority.Low, new MockRefreshAction());
RefreshActionInvoker.InvokeRefreshAction(emptyCacheItem, CacheItemRemovedReason.Expired, instrumentationProvider);
Thread.Sleep(100);
Assert.IsNull(removedValue);
}
示例7: RemovedValueIsGivenToCallbackMethod
public void RemovedValueIsGivenToCallbackMethod()
{
CacheItem emptyCacheItem = new CacheItem("key", "value", CacheItemPriority.Low, new MockRefreshAction());
RefreshActionInvoker.InvokeRefreshAction(emptyCacheItem, CacheItemRemovedReason.Expired, instrumentationProvider);
Thread.Sleep(100);
Assert.AreEqual("value", removedValue);
}
示例8: AddNewItem
/// <summary>
/// Adds new item to persistence store
/// </summary>
/// <param name="storageKey">Unique key for storage item.</param>
/// <param name="newItem">Item to be added to cache. May not be null.</param>
protected override void AddNewItem(int storageKey,
CacheItem newItem)
{
string key = newItem.Key;
byte[] valueBytes = SerializationUtility.ToBytes(newItem.Value);
if (encryptionProvider != null)
{
valueBytes = encryptionProvider.Encrypt(valueBytes);
}
byte[] expirationBytes = SerializationUtility.ToBytes(newItem.GetExpirations());
byte[] refreshActionBytes = SerializationUtility.ToBytes(newItem.RefreshAction);
CacheItemPriority scavengingPriority = newItem.ScavengingPriority;
DateTime lastAccessedTime = newItem.LastAccessedTime;
DbCommand insertCommand = database.GetStoredProcCommand("AddItem");
database.AddInParameter(insertCommand, "@partitionName", DbType.String, partitionName);
database.AddInParameter(insertCommand, "@storageKey", DbType.Int32, storageKey);
database.AddInParameter(insertCommand, "@key", DbType.String, key);
database.AddInParameter(insertCommand, "@value", DbType.Binary, valueBytes);
database.AddInParameter(insertCommand, "@expirations", DbType.Binary, expirationBytes);
database.AddInParameter(insertCommand, "@refreshAction", DbType.Binary, refreshActionBytes);
database.AddInParameter(insertCommand, "@scavengingPriority", DbType.Int32, scavengingPriority);
database.AddInParameter(insertCommand, "@lastAccessedTime", DbType.DateTime, lastAccessedTime);
database.ExecuteNonQuery(insertCommand);
}
示例9: Should_dispose_existing_phoenix
public void Should_dispose_existing_phoenix()
{
var key = "theCacheKey" + Guid.NewGuid();
// Arrange
var objCacheItem = new CacheItem
{
MaxAge = 5,
StaleWhileRevalidate = 5,
StoreId = 1000,
CreatedTime = DateTime.UtcNow.AddSeconds(-5).AddMilliseconds(-1),
Key = key
};
var existingPhoenix = Substitute.For<Phoenix>(Substitute.For<_IInvocation>(), objCacheItem);
var att = new OutputCacheAttributeWithPublicMethods { Duration = 5, CacheStoreId = 1000, StaleWhileRevalidate = 5 };
Global.Cache.PhoenixFireCage[key] = existingPhoenix;
// Action
att.CreatePhoenixPublic(Substitute.For<_IInvocation>(), objCacheItem);
// Assert
Assert.That(Global.Cache.PhoenixFireCage[key] is Phoenix);
existingPhoenix.Received(1).Dispose();
}
示例10: ProcessResponse
protected override bool ProcessResponse(BinaryResponse response)
{
if (response.StatusCode == 0)
{
int flags = BinaryConverter.DecodeInt32(response.Extra, 0);
this.result = new CacheItem((ushort)flags, response.Data);
this.Cas = response.CAS;
#if EVEN_MORE_LOGGING
if (log.IsDebugEnabled)
log.DebugFormat("Get succeeded for key '{0}'.", this.Key);
#endif
return true;
}
this.Cas = 0;
#if EVEN_MORE_LOGGING
if (log.IsDebugEnabled)
log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
#endif
return false;
}
示例11: CanAddMinimalCacheItemToStoreWithItemNotPresent
public void CanAddMinimalCacheItemToStoreWithItemNotPresent()
{
CacheItem cacheItem = new CacheItem("key", new SerializableClass(13), CacheItemPriority.Low, null);
backingStore.Add(cacheItem);
Assert.AreEqual(1, backingStore.Count);
}
示例12: SizeNotZeroWhenOneItemInserted
public void SizeNotZeroWhenOneItemInserted()
{
CacheItem itemToStore = new CacheItem("key", "value", CacheItemPriority.NotRemovable, null);
backingStore.Add(itemToStore);
Assert.AreEqual(1, backingStore.Count, "Inserted item should be in Isolated Storage");
}
示例13: ProcessResponse
protected override IOperationResult ProcessResponse(BinaryResponse response)
{
var status = response.StatusCode;
var result = new BinaryOperationResult();
this.StatusCode = status;
if (status == 0)
{
int flags = BinaryConverter.DecodeInt32(response.Extra, 0);
this.result = new CacheItem((ushort)flags, response.Data);
this.Cas = response.CAS;
#if EVEN_MORE_LOGGING
if (log.IsDebugEnabled)
log.DebugFormat("Get succeeded for key '{0}'.", this.Key);
#endif
return result.Pass();
}
this.Cas = 0;
#if EVEN_MORE_LOGGING
if (log.IsDebugEnabled)
log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
#endif
var message = ResultHelper.ProcessResponseData(response.Data);
return result.Fail(message);
}
示例14: GetThumbnailInternal
private byte[] GetThumbnailInternal(string key, object item,
DlnaMediaTypes type, ref int width,
ref int height)
{
var thumbnailers = thumbers[type];
var rw = width;
var rh = height;
foreach (var thumber in thumbnailers) {
try {
using (var i = thumber.GetThumbnail(item, ref width, ref height)) {
var rv = i.ToArray();
lock (cache) {
cache[key] = new CacheItem(rv, rw, rh);
}
return rv;
}
}
catch (Exception ex) {
Debug(String.Format(
"{0} failed to thumbnail a resource", thumber.GetType()), ex);
continue;
}
}
throw new ArgumentException("Not a supported resource");
}
示例15: GetCacheDataAsync
/// <summary>
/// Retrieves the binary data of the image from the cache.
/// </summary>
/// <param name="item">
/// The record that identifies the image in the cache.
/// </param>
/// <returns>
/// The binary data of the image.
/// </returns>
protected override Task<byte[]> GetCacheDataAsync(CacheItem item)
{
lock (this.cache)
{
return Task.FromResult(this.cache[item]);
}
}