本文整理汇总了C#中NHibernate.Cache.CacheKey类的典型用法代码示例。如果您正苦于以下问题:C# CacheKey类的具体用法?C# CacheKey怎么用?C# CacheKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheKey类属于NHibernate.Cache命名空间,在下文中一共展示了CacheKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary></summary>
public override void Execute()
{
CacheKey ck = null;
if (Persister.HasCache)
{
ck = new CacheKey(
Id,
Persister.IdentifierType,
(string) Persister.IdentifierSpace,
Session.Factory
);
_lock = Persister.Cache.Lock(ck, lastVersion);
}
Persister.Update(Id, state, dirtyFields, hasDirtyCollection, previousState, lastVersion, Instance, Session);
EntityEntry entry = Session.GetEntry(Instance);
if (entry == null)
{
throw new AssertionFailure("possible nonthreadsafe access to session");
}
if (entry.Status == Status.Loaded || Persister.IsVersionPropertyGenerated)
{
// get the updated snapshot of the entity state by cloning current state;
// it is safe to copy in place, since by this time no-one else (should have)
// has a reference to the array
TypeFactory.DeepCopy(
state,
Persister.PropertyTypes,
Persister.PropertyCheckability,
state);
if (Persister.HasUpdateGeneratedProperties)
{
// this entity defines proeprty generation, so process those generated
// values...
Persister.ProcessUpdateGeneratedProperties(Id, Instance, state, Session);
if (Persister.IsVersionPropertyGenerated)
{
nextVersion = Versioning.GetVersion(state, Persister);
}
}
// have the entity entry perform post-update processing, passing it the
// update state and the new version (if one).
entry.PostUpdate(Instance, state, nextVersion);
}
if (Persister.HasCache)
{
if (Persister.IsCacheInvalidationRequired || entry.Status != Status.Loaded)
{
Persister.Cache.Evict(ck);
}
else
{
// TODO: Inefficient if that cache is just going to ignore the updated state!
cacheEntry = new CacheEntry(Instance, Persister, Session);
Persister.Cache.Update(ck, cacheEntry);
}
}
}
示例2: AfterTransactionCompletion
public override void AfterTransactionCompletion(bool success)
{
IEntityPersister persister = Persister;
if (persister.HasCache)
{
CacheKey ck = new CacheKey(Id, persister.IdentifierType, persister.RootEntityName, Session.EntityMode, Session.Factory);
if (success && cacheEntry != null)
{
bool put = persister.Cache.AfterUpdate(ck, cacheEntry, nextVersion, slock);
if (put && Session.Factory.Statistics.IsStatisticsEnabled)
{
Session.Factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
}
}
else
{
persister.Cache.Release(ck, slock);
}
}
if (success)
{
PostCommitUpdate();
}
}
示例3: Put
public bool Put(CacheKey key, object value, long timestamp, object version, IComparer versionComparator,
bool minimalPut)
{
if (timestamp == long.MinValue)
{
// MinValue means cache is disabled
return false;
}
lock (lockObject)
{
if (minimalPut && cache.Get(key) != null)
{
if (log.IsDebugEnabled)
{
log.Debug("item already cached: " + key);
}
return false;
}
if (log.IsDebugEnabled)
{
log.Debug("Caching: " + key);
}
cache.Put(key, value);
return true;
}
}
示例4: InitializeCollectionFromCache
/// <summary> Try to initialize a collection from the cache</summary>
private bool InitializeCollectionFromCache(object id, ICollectionPersister persister, IPersistentCollection collection, ISessionImplementor source)
{
if (!(source.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(source))
{
log.Debug("disregarding cached version (if any) of collection due to enabled filters ");
return false;
}
bool useCache = persister.HasCache && ((source.CacheMode & CacheMode.Get) == CacheMode.Get);
if (!useCache)
{
return false;
}
else
{
ISessionFactoryImplementor factory = source.Factory;
CacheKey ck = new CacheKey(id, persister.KeyType, persister.Role, source.EntityMode, factory);
object ce = persister.Cache.Get(ck, source.Timestamp);
if (factory.Statistics.IsStatisticsEnabled)
{
if (ce == null)
{
factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName);
}
else
{
factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName);
}
}
if (ce == null)
{
log.DebugFormat("Collection cache miss: {0}", ck);
}
else
{
log.DebugFormat("Collection cache hit: {0}", ck);
}
if (ce == null)
{
return false;
}
else
{
IPersistenceContext persistenceContext = source.PersistenceContext;
CollectionCacheEntry cacheEntry = (CollectionCacheEntry)persister.CacheEntryStructure.Destructure(ce, factory);
cacheEntry.Assemble(collection, persister, persistenceContext.GetCollectionOwner(id, persister));
persistenceContext.GetCollectionEntry(collection).PostInitialize(collection);
return true;
}
}
}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:60,代码来源:DefaultInitializeCollectionEventListener.cs
示例5: Execute
public override void Execute()
{
IEntityPersister persister = Persister;
ISessionImplementor session = Session;
object instance = Instance;
object id = Id;
bool veto = PreInsert();
// Don't need to lock the cache here, since if someone
// else inserted the same pk first, the insert would fail
if (!veto)
{
persister.Insert(id, state, instance, Session);
EntityEntry entry = Session.PersistenceContext.GetEntry(instance);
if (entry == null)
{
throw new AssertionFailure("Possible nonthreadsafe access to session");
}
entry.PostInsert();
if (persister.HasInsertGeneratedProperties)
{
persister.ProcessInsertGeneratedProperties(id, instance, state, Session);
if (persister.IsVersionPropertyGenerated)
{
version = Versioning.GetVersion(state, persister);
}
entry.PostUpdate(instance, state, version);
}
}
ISessionFactoryImplementor factory = Session.Factory;
if (IsCachePutEnabled(persister))
{
CacheEntry ce = new CacheEntry(state, persister, persister.HasUninitializedLazyProperties(instance, session.EntityMode), version, session, instance);
cacheEntry = persister.CacheEntryStructure.Structure(ce);
CacheKey ck = new CacheKey(id, persister.IdentifierType, persister.RootEntityName, Session.EntityMode, Session.Factory);
bool put = persister.Cache.Insert(ck, cacheEntry, version);
if (put && factory.Statistics.IsStatisticsEnabled)
{
factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
}
}
PostInsert();
if (factory.Statistics.IsStatisticsEnabled && !veto)
{
factory.StatisticsImplementor.InsertEntity(Persister.EntityName);
}
}
示例6: Get
public object Get(CacheKey key, long timestamp)
{
object result = cache.Get(key);
if (result != null && log.IsDebugEnabled)
{
log.Debug("Cache hit: " + key);
}
return result;
}
示例7: UpgradeLock
/// <summary>
/// Performs a pessimistic lock upgrade on a given entity, if needed.
/// </summary>
/// <param name="entity">The entity for which to upgrade the lock.</param>
/// <param name="entry">The entity's EntityEntry instance.</param>
/// <param name="requestedLockMode">The lock mode being requested for locking. </param>
/// <param name="source">The session which is the source of the event being processed.</param>
protected virtual void UpgradeLock(object entity, EntityEntry entry, LockMode requestedLockMode, ISessionImplementor source)
{
if (requestedLockMode.GreaterThan(entry.LockMode))
{
// The user requested a "greater" (i.e. more restrictive) form of
// pessimistic lock
if (entry.Status != Status.Loaded)
{
throw new ObjectDeletedException("attempted to lock a deleted instance", entry.Id, entry.EntityName);
}
IEntityPersister persister = entry.Persister;
if (log.IsDebugEnabled)
{
log.Debug(string.Format("locking {0} in mode: {1}", MessageHelper.InfoString(persister, entry.Id, source.Factory), requestedLockMode));
}
ISoftLock slock;
CacheKey ck;
if (persister.HasCache)
{
ck = new CacheKey(entry.Id, persister.IdentifierType, persister.RootEntityName, source.EntityMode, source.Factory);
slock = persister.Cache.Lock(ck, entry.Version);
}
else
{
ck = null;
slock = null;
}
try
{
if (persister.IsVersioned && requestedLockMode == LockMode.Force)
{
// todo : should we check the current isolation mode explicitly?
object nextVersion = persister.ForceVersionIncrement(entry.Id, entry.Version, source);
entry.ForceLocked(entity, nextVersion);
}
else
{
persister.Lock(entry.Id, entry.Version, entity, requestedLockMode, source);
}
entry.LockMode = requestedLockMode;
}
finally
{
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if (persister.HasCache)
{
persister.Cache.Release(ck, slock);
}
}
}
}
示例8: AfterTransactionCompletion
public override void AfterTransactionCompletion(bool success)
{
if (Persister.HasCache)
{
CacheKey ck = new CacheKey(Id, Persister.IdentifierType, Persister.RootEntityName, Session.EntityMode, Session.Factory);
Persister.Cache.Release(ck, sLock);
}
if (success)
{
PostCommitDelete();
}
}
示例9: AfterTransactionCompletion
/// <summary></summary>
public override void AfterTransactionCompletion(bool success)
{
if (Persister.HasCache)
{
CacheKey ck = new CacheKey(
Id,
Persister.IdentifierType,
(string) Persister.IdentifierSpace,
Session.Factory
);
Persister.Cache.Release(ck, lck);
}
}
示例10: AfterTransactionCompletion
/// <summary></summary>
public override void AfterTransactionCompletion(bool success)
{
// Make 100% certain that this is called before any subsequent ScheduledUpdate.AfterTransactionCompletion()!!
if (success && Persister.HasCache && !Persister.IsCacheInvalidationRequired)
{
CacheKey ck = new CacheKey(
Id,
Persister.IdentifierType,
(string) Persister.IdentifierSpace,
Session.Factory
);
Persister.Cache.AfterInsert(ck, cacheEntry, version);
}
}
示例11: Get
/// <summary>
/// Do not return an item whose timestamp is later than the current
/// transaction timestamp. (Otherwise we might compromise repeatable
/// read unnecessarily.) Do not return an item which is soft-locked.
/// Always go straight to the database instead.
/// </summary>
/// <remarks>
/// Note that since reading an item from that cache does not actually
/// go to the database, it is possible to see a kind of phantom read
/// due to the underlying row being updated after we have read it
/// from the cache. This would not be possible in a lock-based
/// implementation of repeatable read isolation. It is also possible
/// to overwrite changes made and committed by another transaction
/// after the current transaction read the item from the cache. This
/// problem would be caught by the update-time version-checking, if
/// the data is versioned or timestamped.
/// </remarks>
public object Get(CacheKey key, long txTimestamp)
{
lock (_lockObject)
{
if (log.IsDebugEnabled)
{
log.Debug("Cache lookup: " + key);
}
// commented out in H3.1
/*try
{
cache.Lock( key );*/
ILockable lockable = (ILockable) cache.Get(key);
bool gettable = lockable != null && lockable.IsGettable(txTimestamp);
if (gettable)
{
if (log.IsDebugEnabled)
{
log.Debug("Cache hit: " + key);
}
return ((CachedItem) lockable).Value;
}
else
{
if (log.IsDebugEnabled)
{
if (lockable == null)
{
log.Debug("Cache miss: " + key);
}
else
{
log.Debug("Cached item was locked: " + key);
}
}
return null;
}
/*}
finally
{
cache.Unlock( key );
}*/
}
}
示例12: Execute
/// <summary></summary>
public override void Execute()
{
if (Persister.HasCache)
{
CacheKey ck = new CacheKey(
Id,
Persister.IdentifierType,
(string) Persister.IdentifierSpace,
Session.Factory
);
lck = Persister.Cache.Lock(ck, version);
}
Persister.Delete(Id, version, Instance, Session);
Session.PostDelete(Instance);
}
示例13: SecondLevelCachedCollectionsFiltering
public void SecondLevelCachedCollectionsFiltering()
{
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
// Force a collection into the second level cache, with its non-filtered elements
Salesperson sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
NHibernateUtil.Initialize(sp.Orders);
ICollectionPersister persister = ((ISessionFactoryImplementor) sessions)
.GetCollectionPersister(typeof(Salesperson).FullName + ".Orders");
Assert.IsTrue(persister.HasCache, "No cache for collection");
CacheKey cacheKey =
new CacheKey(testData.steveId, persister.KeyType, persister.Role, EntityMode.Poco, (ISessionFactoryImplementor) sessions);
CollectionCacheEntry cachedData = (CollectionCacheEntry)persister.Cache.Cache.Get(cacheKey);
Assert.IsNotNull(cachedData, "collection was not in cache");
session.Close();
session = OpenSession();
session.EnableFilter("fulfilledOrders").SetParameter("asOfDate", testData.lastMonth);
sp = (Salesperson) session.CreateQuery("from Salesperson as s where s.id = :id")
.SetInt64("id", testData.steveId)
.UniqueResult();
Assert.AreEqual(1, sp.Orders.Count, "Filtered-collection not bypassing 2L-cache");
CollectionCacheEntry cachedData2 = (CollectionCacheEntry)persister.Cache.Cache.Get(cacheKey);
Assert.IsNotNull(cachedData2, "collection no longer in cache!");
Assert.AreSame(cachedData, cachedData2, "Different cache values!");
session.Close();
session = OpenSession();
session.EnableFilter("fulfilledOrders").SetParameter("asOfDate", testData.lastMonth);
sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
Assert.AreEqual(1, sp.Orders.Count, "Filtered-collection not bypassing 2L-cache");
session.Close();
// Finally, make sure that the original cached version did not get over-written
session = OpenSession();
sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
Assert.AreEqual(2, sp.Orders.Count, "Actual cached version got over-written");
session.Close();
testData.Release();
}
示例14: Get
/// <summary>
/// Get the most recent version, if available.
/// </summary>
public object Get(CacheKey key, long txTimestamp)
{
if (log.IsDebugEnabled)
{
log.Debug("Cache lookup: " + key);
}
object result = cache.Get(key);
if (result != null)
{
log.Debug("Cache hit");
}
else
{
log.Debug("Cache miss");
}
return result;
}
示例15: AfterTransactionCompletion
public override void AfterTransactionCompletion(bool success)
{
//Make 100% certain that this is called before any subsequent ScheduledUpdate.afterTransactionCompletion()!!
IEntityPersister persister = Persister;
if (success && IsCachePutEnabled(persister))
{
CacheKey ck = new CacheKey(Id, persister.IdentifierType, persister.RootEntityName, Session.EntityMode, Session.Factory);
bool put = persister.Cache.AfterInsert(ck, cacheEntry, version);
if (put && Session.Factory.Statistics.IsStatisticsEnabled)
{
Session.Factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName);
}
}
if (success)
{
PostCommitInsert();
}
}