Beispiel #1
0
        public Task <OpResponse> QueryResponse <M>(string key, object criteria, int?freshnessSeconds = null)
        {
            var req = RequestOp.QueryOp <M>(
                key,
                criteria,
                NowMs,
                freshnessSeconds ?? Config.DefaultFreshnessSeconds
                );

            return(ProcessRequest(req));
        }
Beispiel #2
0
        public async Task TestCollections()
        {
            var path = System.IO.Path.GetTempFileName();
            var conn = new SQLite.SQLiteAsyncConnection(path);
            var db   = new TestDatabase(conn);
            await db.Reset();

            var sqliteThingCache = new SqliteClassCache <Parent, long>(db);
            await sqliteThingCache.Setup();

            var sqliteGadgetCache = new SqliteClassCache <Child, string>(db);
            await sqliteGadgetCache.Setup();

            var cache = new ModelCache(aClassCache: new Dictionary <Type, IModelClassCache>()
            {
                { typeof(Parent), sqliteThingCache },
                { typeof(Child), sqliteGadgetCache }
            });
            var cascade = new CascadeDataLayer(origin, new ICascadeCache[] { cache }, new CascadeConfig()
            {
                DefaultFreshnessSeconds = 1
            });

            var collection_key = "my_things";
            var ids            = ImmutableArray.Create <object>(1, 2, 3);
            var response       = await cache.Fetch(RequestOp.QueryOp <Parent>(collection_key, new JsonObject(), 0));

            Assert.AreEqual(false, response.Exists);
            Assert.AreEqual(null, response.Result);
            await cache.StoreCollection(typeof(Parent), collection_key, ids, 0);

            response = await cache.Fetch(RequestOp.QueryOp <Parent>(collection_key, null, 0));

            Assert.IsTrue(CascadeTypeUtils.IsEqualEnumerable(ids, response.ResultIds));

            response = await cache.Fetch(RequestOp.QueryOp <Parent>("not_my_key", null, 0));

            Assert.IsFalse(response.Exists);

            response = await cache.Fetch(RequestOp.QueryOp <Child>(collection_key, null, 0));

            Assert.IsFalse(response.Exists);
        }