コード例 #1
0
        /// <summary>
        ///     This method is called when a transaction event occurs.
        /// </summary>
        /// <param name="transactionEvent">The transaction event</param>
        void ITransactionEventNotification.OnTransactionEvent(TransactionEventNotificationArgs transactionEvent)
        {
            switch (transactionEvent.EventType)
            {
            case TransactionEventType.Commit:
                ICache <TKey, TValue> cache;

                // Remove the cache from the list of caches
                _privateCaches.TryRemove(transactionEvent.Transactionid, out cache);

                // If there was a private cache, then commit it to the public cache
                if (cache != null)
                {
                    var publicCache = GetPublicCache();
                    foreach (var kvp in cache)
                    {
                        TKey   key   = kvp.Key;
                        TValue value = kvp.Value;

                        Add(key, value, publicCache, false);
                    }
                }
                break;

            case TransactionEventType.Rollback:
                // Remove the transaction specific data.
                _privateCaches.TryRemove(transactionEvent.Transactionid, out cache);
                break;
            }
        }
            /// <summary>
            /// </summary>
            /// <param name="transactionEvent"></param>
            void ITransactionEventNotification.OnTransactionEvent(TransactionEventNotificationArgs transactionEvent)
            {
                lock ( _syncRoot )
                {
                    switch (transactionEvent.EventType)
                    {
                    case TransactionEventType.Commit:
                        // Remove the cache from the list of caches
                        HashSet <string> cache;
                        if (_cachedItems.TryGetValue(transactionEvent.Transactionid, out cache))
                        {
                            _cachedItems.Remove(transactionEvent.Transactionid);

                            // Commit all the data from the transaction specific cache
                            // to the default cache.
                            foreach (string s in cache)
                            {
                                HashSet <string> defaultCache = GetCache(true);
                                defaultCache.Add(s);
                            }
                        }
                        break;

                    case TransactionEventType.Rollback:
                        _cachedItems.Remove(transactionEvent.Transactionid);
                        break;
                    }
                }
            }