本文整理汇总了C#中CacheItem类的典型用法代码示例。如果您正苦于以下问题:C# CacheItem类的具体用法?C# CacheItem怎么用?C# CacheItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheItem类属于命名空间,在下文中一共展示了CacheItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
}
开发者ID:v0id24,项目名称:naps2,代码行数:30,代码来源:ThumbnailCache.cs
示例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) ;
}
开发者ID:priceLiu,项目名称:imgListView,代码行数:36,代码来源:ImageListViewCacheManager.cs
示例3: StoreOperation
public StoreOperation(StoreMode mode, string key, CacheItem value, uint expires)
: base(key)
{
this.mode = mode;
this.value = value;
this.expires = expires;
}
开发者ID:bcui6611,项目名称:EnyimMemcached,代码行数:7,代码来源:StoreOperation.cs
示例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);
}
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:29,代码来源:ScavengerFixture.cs
示例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);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:7,代码来源:RefreshActionInvokerFixture.cs
示例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);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:7,代码来源:RefreshActionInvokerFixture.cs
示例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);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:7,代码来源:RefreshActionInvokerFixture.cs
示例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);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:32,代码来源:DataBackingStore.cs
示例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();
}
开发者ID:vanthoainguyen,项目名称:Flatwhite,代码行数:26,代码来源:OutputCacheAttributeTests.cs
示例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;
}
开发者ID:simonthorogood,项目名称:EnyimMemcached,代码行数:25,代码来源:GetOperation.cs
示例11: CanAddMinimalCacheItemToStoreWithItemNotPresent
public void CanAddMinimalCacheItemToStoreWithItemNotPresent()
{
CacheItem cacheItem = new CacheItem("key", new SerializableClass(13), CacheItemPriority.Low, null);
backingStore.Add(cacheItem);
Assert.AreEqual(1, backingStore.Count);
}
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:7,代码来源:DataBackingStoreFixture.cs
示例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");
}
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:7,代码来源:IsolatedStorageBackingStoreFixture.cs
示例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);
}
开发者ID:JebteK,项目名称:couchbase-net-client,代码行数:31,代码来源:GetOperation.cs
示例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");
}
开发者ID:modulexcite,项目名称:simpleDLNA,代码行数:25,代码来源:ThumbnailMaker.cs
示例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]);
}
}
开发者ID:mdabbagh88,项目名称:UniversalImageLoader,代码行数:16,代码来源:MemoryImageLoader.cs
示例16: GetCacheExpirations
public static ICacheExpiration[] GetCacheExpirations(CacheItem item)
{
lastTimeAccessed = item.LastAccessedTime;
var expirations = new List<ICacheExpiration>();
switch (item.GetCacheItemType())
{
case CacheItemType.Object:
expirations.AddRange(GetTimeExpirations(true, true));
break;
case CacheItemType.Page:
expirations.AddRange(GetTimeExpirations(true, true));
break;
case CacheItemType.Collection:
expirations.AddRange(GetTimeExpirations(true, true));
break;
}
return expirations.ToArray();
}
开发者ID:Gotik88,项目名称:LoanProcess,代码行数:25,代码来源:CacheItemExpirationsFactory.cs
示例17: StoreOperation
IStoreOperation IOperationFactory.Store(StoreMode mode, string key, CacheItem value, uint expires, ulong cas)
{
if (cas == 0)
return new StoreOperation(mode, key, value, expires);
return new CasOperation(key, value, expires, (uint)cas);
}
开发者ID:javithalion,项目名称:NCache,代码行数:7,代码来源:TextOperationFactory.cs
示例18: Memcached_KeySizeLimit_WithRegion
public void Memcached_KeySizeLimit_WithRegion()
{
// arrange
var longKey = string.Join(string.Empty, Enumerable.Repeat("a", 300));
var item = new CacheItem<string>(longKey, "someRegion", "something");
var cache = CacheFactory.Build<string>(settings =>
{
settings.WithUpdateMode(CacheUpdateMode.Full)
.WithMemcachedCacheHandle("default")
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMinutes(1));
});
// act
using (cache)
{
cache.Remove(item.Key, item.Region);
Func<bool> act = () => cache.Add(item);
Func<string> act2 = () => cache[item.Key, item.Region];
// assert
act().Should().BeTrue();
act2().Should().Be(item.Value);
}
}
开发者ID:yue-shi,项目名称:CacheManager,代码行数:25,代码来源:MemcachedTests.cs
示例19: CallbackDoesHappenIfRefreshActionIsSet
public void CallbackDoesHappenIfRefreshActionIsSet()
{
CacheItem emptyCacheItem = new CacheItem("key", "value", CacheItemPriority.Low, new MockRefreshAction());
RefreshActionInvoker.InvokeRefreshAction(emptyCacheItem, CacheItemRemovedReason.Expired, instrumentationProvider);
Thread.Sleep(100);
Assert.IsTrue(callbackHappened);
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:7,代码来源:RefreshActionInvokerFixture.cs
示例20: ImageListViewCacheThumbnail
/// <summary>
/// Initializes a new instance of the <see cref="ImageListViewCacheThumbnail"/> class.
/// </summary>
/// <param name="owner">The owner control.</param>
public ImageListViewCacheThumbnail(ImageListView owner)
{
context = null;
bw = new QueuedBackgroundWorker();
bw.ProcessingMode = ProcessingMode.LIFO;
bw.IsBackground = true;
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
checkProcessingCallback = new SendOrPostCallback(CanContinueProcessing);
mImageListView = owner;
CacheMode = CacheMode.OnDemand;
CacheLimitAsItemCount = 0;
CacheLimitAsMemory = 20 * 1024 * 1024;
RetryOnError = false;
thumbCache = new Dictionary<Guid, CacheItem>();
editCache = new Dictionary<Guid, bool>();
processing = new Dictionary<Guid, bool>();
processingRendererItem = Guid.Empty;
processingGalleryItem = Guid.Empty;
rendererItem = null;
galleryItem = null;
MemoryUsed = 0;
MemoryUsedByRemoved = 0;
removedItems = new List<Guid>();
disposed = false;
}
开发者ID:zebulon75018,项目名称:mauriceadmin,代码行数:36,代码来源:ImageListViewCacheThumbnail.cs
注:本文中的CacheItem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论