Ejemplo n.º 1
0
 public object Any(TestCacheError request)
 {
     return(Request.ToOptimizedResultUsingCache(this.Cache,
                                                UrnId.CreateWithParts("15", request.GetType().Name), TimeSpan.FromSeconds(20), () =>
     {
         return request;
     }));
 }
Ejemplo n.º 2
0
 public object Any(DefaultRequest request)
 {
     return(Request.ToOptimizedResultUsingCache(this.Cache, UrnId.CreateWithParts("15", "dummy"), TimeSpan.FromMilliseconds(20000), () =>
     {
         return new DefaultResult
         {
         };
     }));
 }
Ejemplo n.º 3
0
        public static void CacheAllWorlds(this MongoDatabase db, ICacheClient cache, string dbType)
        {
            cache.FlushAll();

            // concurrently create a list of world ids
            var worlds = db.GetWorlds();

            Parallel.ForEach <World>(worlds, w =>
            {
                var cacheKey = UrnId.CreateWithParts <World>(new string[] { dbType, w.id.ToString() });

                cache.Set <World>(cacheKey, w);
            });
        }
Ejemplo n.º 4
0
        public object Get(SqlServerCachedDbRequest request)
        {
            // get a random world id
            var id = SafeRandom.Instance.Next(0, 10000) + 1;

            // create the cache key for the random world id
            var cacheKey = UrnId.CreateWithParts <World>(new string[] { dbType, id.ToString() });

            // if world is cached, return it
            var world = Cache.Get <World>(cacheKey);

            if (world != null)
            {
                return(world);
            }

            // get all of the worlds form the database
            List <World> worlds;

            using (var db = dbFactory.OpenDbConnection())
            {
                worlds = db.GetWorlds();
            }

            // construct a cache dictionary
            var cacheDict = new Dictionary <string, World>();

            Parallel.ForEach(worlds, w =>
            {
                // collect the current result
                if (w.id == id)
                {
                    world = w;
                }

                // add world to cache dictionary
                var key = UrnId.CreateWithParts <World>(new string[] { dbType, w.id.ToString() });
                lock (cacheDict)
                {
                    cacheDict.Add(key, w);
                }
            });

            // populate cache
            Cache.SetAll <World>(cacheDict);

            // return current request
            return(world);
        }