コード例 #1
0
 internal EnyimIndexCreator(EnyimTableCache parent, string indexKeyInCache, SearchConditions searchConditions)
 {
     this._parent          = parent;
     this._index           = new TableIndex(searchConditions);
     this._indexKey        = searchConditions.Key;
     this._indexKeyInCache = indexKeyInCache;
 }
コード例 #2
0
 internal EnyimProjectionIndexCreator(EnyimTableCache parent, string indexKey, string indexKeyInCache, SearchConditions searchConditions)
 {
     this._parent = parent;
     this._index = new TableProjectionIndex(searchConditions);
     this._indexKey = indexKey;
     this._indexKeyInCache = indexKeyInCache;
 }
コード例 #3
0
        public override void SetUp()
        {
            this.Context = TestConfiguration.GetDataContext();

            this.CacheClient = new MemcachedClient();

            this.CacheClient.FlushAll();
            this._cacheHitCount = 0;

            this.TableCache = GetEnyimTableCache(this.CacheClient);
            this.TableCache.OnHit += () => this._cacheHitCount++;
            this.TableCache.OnLog += s => Logger.Debug(s);
        }
コード例 #4
0
ファイル: TableLock.cs プロジェクト: LCHarold/linq2dynamodb
 internal TableLock(EnyimTableCache repository, string lockKey, TimeSpan lockTimeout)
 {
     this._cache = repository;
     this._lockKey = lockKey;
     this._cache.LockTable(lockKey, lockTimeout);
 }
コード例 #5
0
 internal EnyimIndexCreator(EnyimTableCache parent, string indexKeyInCache, SearchConditions searchConditions)
     : base(parent, indexKeyInCache, searchConditions)
 {
 }
コード例 #6
0
		public void DataContext_Caching_UserSpecificIndexUpdatedByFullIndex()
		{
			cacheClient.FlushAll();
			this._cacheHitCount = 0;

            var ctx = TestConfiguration.GetDataContext();

			var fullTable = ctx.GetTable<FullEntity>(() =>
				{
					var cache = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
					cache.OnLog += s => Debug.WriteLine("{0} FullEntityCache: {1}", DateTime.Now, s);
				    cache.OnHit += this.OnCacheHit;
					return cache;
				});

			var userSpecificTable1 = ctx.GetTable<UserEntity>
			(
				userId1,
				() =>
				{
					var cache = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
					cache.OnLog += s => Debug.WriteLine("{0} UserEntityCache1: {1}", DateTime.Now, s);
                    cache.OnHit += this.OnCacheHit;
                    return cache;
				}
			);

            var userSpecificTable2 = ctx.GetTable<UserEntity>
            (
                userId2,
                () =>
                {
                    var cache = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
                    cache.OnLog += s => Debug.WriteLine("{0} UserEntityCache2: {1}", DateTime.Now, s);
                    cache.OnHit += this.OnCacheHit;
                    return cache;
                }
            );

			var fullQuery = from en in fullTable where en.DateTimeField >= dtNow && (intRange.Contains(en.IntField)) select en;
			var userSpecificQuery1 = from en in userSpecificTable1 where en.DateTimeField >= dtNow && (intRange.Contains(en.IntField)) select en;
            var userSpecificQuery2 = from en in userSpecificTable2 where en.DateTimeField < dtNow && en.IntField < 3 select en;

			// loading indexes - they should be put to cache
			Assert.AreEqual(2, fullQuery.AsEnumerable().Count(), "Failed to load full query from table");
			Assert.AreEqual(1, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query1 from table");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(0, this._cacheHitCount, "Cache wasn't flushed for some strange reason");

			// now loading from cache
			Assert.AreEqual(2, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
			Assert.AreEqual(1, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");

            // now adding 2 new entities - they should appear in both indexes
            fullTable.InsertOnSubmit
            (
                new FullEntity()
                {
                    HashKey = userId1,
                    RangeKey = rangeKey5,
                    DateTimeField = dtNow + TimeSpan.FromDays(1000),
                    IntField = 5
                }
            );
            fullTable.InsertOnSubmit
            (
                new FullEntity()
                {
                    HashKey = userId1,
                    RangeKey = rangeKey4,
                    DateTimeField = dtNow + TimeSpan.FromDays(9999),
                    IntField = 4
                }
            );
            ctx.SubmitChanges();

		    this._cacheHitCount = 0;

            // now loading from cache
            Assert.AreEqual(4, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(3, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");


            // now removing a couple of entities

            fullTable.RemoveOnSubmit(new FullEntity() { HashKey = userId1, RangeKey = rangeKey1 });
            fullTable.RemoveOnSubmit(new FullEntity() { HashKey = userId1, RangeKey = rangeKey3 });
            ctx.SubmitChanges();

            this._cacheHitCount = 0;

            // now loading from cache
            Assert.AreEqual(3, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(2, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");

            // now loading from DynamoDb again
            cacheClient.FlushAll();
            this._cacheHitCount = 0;

            Assert.AreEqual(3, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(2, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(0, this._cacheHitCount, "Cache wasn't flushed for some strange reason");
        } 
コード例 #7
0
ファイル: TableLock.cs プロジェクト: dguisinger/linq2dynamodb
 internal TableLock(EnyimTableCache repository, string lockKey, TimeSpan lockTimeout)
 {
     this._cache   = repository;
     this._lockKey = lockKey;
     this._cache.LockTable(lockKey, lockTimeout);
 }