Beispiel #1
0
        public void CachedLambdaCompiler_Simple3b()
        {
            var added = 0;

            var c = new MyCache();

            c.Added += () => added++;

            Expression <Func <int, int> > f1 = x => x + 1;
            Expression <Func <int, int> > f2 = x => x + 2;
            Expression <Func <int, int> > f3 = y => y + 3;

            var d1 = f1.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            var d2 = f2.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            var d3 = f3.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            Assert.AreEqual(43, d1(42));
            Assert.AreEqual(46, d2(44));
            Assert.AreEqual(49, d3(46));
        }
Beispiel #2
0
 void Update()
 {
     if (Time.time > spawnTime + lifeTime)
     {
         MyCache.Destroy(gameObject);// get rid of the entity if too old
     }
 }
        /// <summary>
        /// 获取展会所有展商地址
        /// </summary>
        /// <param name="exhibitionID"></param>
        /// <returns></returns>
        public DataTable GetExhibitorLocation(int exhibitionID)
        {
            string key = string.Format(WebKeys.ExhibitorLocationConsoleCacheKey, exhibitionID.ToString());
            DataTableRSCacheEntity rsobj = MyCache <DataTableRSCacheEntity> .Get(key);

            if (rsobj == null)
            {
                DataTable dt = dao.GetExhibitorLocation(exhibitionID);
                if (dt != null && dt.Rows.Count > 0)
                {
                    rsobj = new DataTableRSCacheEntity()
                    {
                        Source = dt, TotalCnt = dt.Rows.Count
                    };
                    MyCache <DataTableRSCacheEntity> .Insert(key, rsobj, 60);
                }
                else
                {
                    rsobj = new DataTableRSCacheEntity();
                }
            }
            return(rsobj.Source);

            //return dao.GetExhibitorLocation(exhibitionID);
        }
        public override Composite GetComposite(ExtensionParameter profileParameter)
        {
            return(new TreeSharp.Action((x) =>
            {
                if (profileParameter.Plugin.ExtensionCache.Cache.TryGetValue(Owner, out Dictionary <string, object> MyCache))
                {
                    var timerCacheString = DefaultExtension.CustomerTimerPrefix + TimerName;
                    Stopwatch stopWatch = null;
                    if (!MyCache.TryGetValue(timerCacheString, out object value))
                    {
                        stopWatch = new Stopwatch();
                        MyCache[timerCacheString] = stopWatch;
                    }
                    else
                    {
                        stopWatch = (Stopwatch)value;
                    }

                    if (ForceStop)
                    {
                        // We need to start the timer, and it isn't in the cache already
                        stopWatch.Stop();
                    }
                    else
                    {
                        stopWatch.Restart();
                    }
                }
                else
                {
                    profileParameter.Plugin.LogErr(Name + " is unable to get cache!", 5);
                }
            }));
        }
        public override Func <bool> GetCondition(ExtensionParameter extensionParameter)
        {
            return(() =>
            {
                if (extensionParameter.Plugin.ExtensionCache.Cache.TryGetValue(Owner, out Dictionary <string, object> MyCache))
                {
                    var timerCacheString = DefaultExtension.CustomerTimerPrefix + TimerNameString;
                    if (MyCache.TryGetValue(timerCacheString, out object value))
                    {
                        Stopwatch stopWatch = (Stopwatch)value;
                        return stopWatch.ElapsedMilliseconds >= TimeElapsed;
                    }
                    else
                    {
                        return TrueIfStopped;
                    }
                }
                else
                {
                    extensionParameter.Plugin.LogErr(Name + " is unable to get cache!", 5);
                }

                return false;
            });
        }
Beispiel #6
0
        public void CachedLambdaCompiler_OutliningDisabled()
        {
            var added = 0;

            var cache = new MyCache();

            cache.Added += () => added++;

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f1 = xs => xs.Where(x => x > 1).Select(x => x * 2);
            var d1 = f1.Compile(cache, outliningEnabled: false);
            var r1 = d1(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { 4, 6, 8 }.SequenceEqual(r1));
            Assert.AreEqual(1, added);

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f2 = xs => xs.Where(x => x > 0).Select(x => x * 3);
            var d2 = f2.Compile(cache, outliningEnabled: false);
            var r2 = d2(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { 3, 6, 9, 12 }.SequenceEqual(r2));
            Assert.AreEqual(1, added);

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f3 = xs => xs.OrderBy(x => x * -1).Where(x => x > 2).Select(x => x * -2);
            var d3 = f3.Compile(cache, outliningEnabled: false);
            var r3 = d3(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { -8, -6 }.SequenceEqual(r3));
            Assert.AreEqual(2, added);
        }
        public void MemoizationCacheBase_Simple()
        {
            var cleared   = false;
            var disposing = false;

            var c = new MyCache
            {
                CountF        = () => 42,
                DebugViewF    = () => "foo",
                ClearA        = b => { Assert.AreEqual(disposing, b); cleared = true; },
                GetOrAddCoreF = x => x + 1,
            };

            Assert.AreEqual(42, c.Count);
            Assert.AreEqual("foo", c.DebugView);
            Assert.AreEqual(2, c.GetOrAdd(1));

            cleared   = false;
            disposing = false;
            c.Clear();
            Assert.IsTrue(cleared);

            cleared   = false;
            disposing = true;
            c.Dispose();
            Assert.IsTrue(cleared);

            Assert.AreEqual(0, c.Count);
            Assert.AreNotEqual("foo", c.DebugView);

            Assert.ThrowsException <ObjectDisposedException>(() => c.GetOrAdd(2));
        }
Beispiel #8
0
        /// <summary>
        /// 使用缓存查询信息
        /// </summary>
        /// <param name="info">查询主体</param>
        /// <param name="totalcnt">返回条目数</param>
        /// <returns></returns>
        public DataTable QueryData(ActivitySearchEntity info, out int totalcnt)
        {
            if (info.UseDBPagination)
            {
                string key = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(info.ToJson(info), "MD5");
                DataTableRSCacheEntity rsobj = MyCache <DataTableRSCacheEntity> .Get(key);

                if (rsobj == null)
                {
                    DataTable dt = dao.QueryData(info, out totalcnt);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        rsobj = new DataTableRSCacheEntity()
                        {
                            Source = dt, TotalCnt = totalcnt
                        };
                        MyCache <DataTableRSCacheEntity> .Insert(key, rsobj, 60);
                    }
                    else
                    {
                        rsobj = new DataTableRSCacheEntity();
                    }
                }
                totalcnt = rsobj.TotalCnt;
                return(rsobj.Source);
            }
            else
            {
                return(dao.QueryData(info, out totalcnt));
            }
        }
Beispiel #9
0
        public void CachedLambdaCompiler_OutliningEnabled_Lambda()
        {
            var added = 0;

            var cache = new MyCache();

            cache.Added += () => added++;

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f1 = xs => xs.Where(x => x > 1).Select(x => x * 2).ToArray();
            var d1 = ((LambdaExpression)f1).Compile(cache, outliningEnabled: true);
            var r1 = (int[])d1.DynamicInvoke(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { 4, 6, 8 }.SequenceEqual(r1));
            Assert.AreEqual(3, added);

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f2 = xs => xs.Where(x => x > 0).Select(x => x * 3).ToArray();
            var d2 = ((LambdaExpression)f2).Compile(cache, outliningEnabled: true);
            var r2 = (int[])d2.DynamicInvoke(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { 3, 6, 9, 12 }.SequenceEqual(r2));
            Assert.AreEqual(3, added);

            Expression <Func <IEnumerable <int>, IEnumerable <int> > > f3 = xs => xs.OrderBy(x => x * -1).Where(x => x > 2).Select(x => x * -2).ToArray();
            var d3 = ((LambdaExpression)f3).Compile(cache, outliningEnabled: true);
            var r3 = (int[])d3.DynamicInvoke(new[] { 1, 2, 3, 4 });

            Assert.IsTrue(new[] { -8, -6 }.SequenceEqual(r3));
            Assert.AreEqual(4, added);
        }
Beispiel #10
0
        public void CachedLambdaCompiler_Simple2b()
        {
            var added = 0;

            var c = new MyCache();

            c.Added += () => added++;

            Expression <Func <int> > f1 = () => 42;
            Expression <Func <int> > f2 = () => 43;
            Expression <Func <int> > f3 = () => 44;

            var d1 = f1.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            var d2 = f1.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            var d3 = f2.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            var d4 = f3.Compile(c, outliningEnabled: false);

            Assert.AreEqual(1, added);

            Assert.AreEqual(42, d1());
            Assert.AreEqual(42, d2());
            Assert.AreEqual(43, d3());
            Assert.AreEqual(44, d4());
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            var keys = new string[] { "a", "i", "u", "e", "o" };
            var myCache = new MyCache();
            myCache.set_Item(keys[0], 1);
            myCache.set_Item(keys[1], "mogeta");
            myCache.set_Item(keys[2], new A() { Key = 10, Value = "hoge" });
            myCache.set_Item(keys[3], new DateTime(2011, 5, 19, 23, 56, 41));
            myCache.set_Item(keys[4], 10d);

            Console.WriteLine("MyCache.Count: {0}", myCache.Count);
            for (int i = 0; i < keys.Length; i++)
            {
                Console.WriteLine("MyCache[{0}]: {1}", keys[i], myCache.get_Item(keys[i]));
            }
            // Messages will display as below:
            // MyCache[a]: 1
            // MyCache[i]: mogeta
            // MyCache[u]: Sample02Test.A
            // MyCache[e]: 2011/05/19 23:56:41
            // MyCache[o]: 10
            //
            Console.WriteLine();
            Console.WriteLine("--------------------------------------------------");
            Console.WriteLine();

            foreach (PairStrVariant item in myCache)
            {
                Console.WriteLine("MyCache[{0}]: {1}", item.First, item.Second);
            }
            // Messages will display as below:
            // MyCache[i]: mogeta
            // MyCache[u]: Sample02Test.A
            // MyCache[a]: 1
            // MyCache[o]: 10
            // MyCache[e]: 2011/05/19 23:56:41
            //
            Console.WriteLine();
            Console.WriteLine("--------------------------------------------------");
            Console.WriteLine();

            myCache.set_Item("f", new NotImplemented());
            var printer = new MyCachePrinter();
            try
            {
                printer.Print();
                // Messages will display as below:
                // MyCache[i]:  mogeta
                // MyCache[u]:  Sample02Test.A
                // MyCache[a]:   1
                // MyCache[o]:  10
                // MyCache[e]:  2011/05/19 23:56:42
            }
            catch (NotImplementedException e)
            {
                Console.WriteLine(e.Message);   // Message will display as "Error, World !!".
            }

            Console.ReadLine();
        }
 static void ShowResult(MyCache cache0, MyCache cache1, string key, string caption)
 {
     Console.WriteLine(caption);
     byte[] blob0 = cache0.Get(key), blob1 = cache1.Get(key);
     Console.WriteLine("{0} vs {1}",
                       blob0 == null ? "(null)" : Encoding.UTF8.GetString(blob0),
                       blob1 == null ? "(null)" : Encoding.UTF8.GetString(blob1)
                       );
 }
        public void MemoizationCacheExtensions_ToTrimmable_HasService()
        {
            var c = new MyCache <int, int>(hasServices: true);

            Assert.IsNotNull(MemoizationCacheExtensions.ToTrimmableByMetrics(c));
            Assert.IsNotNull(MemoizationCacheExtensions.ToTrimmableByArgumentAndResult <int, int>(c));
            Assert.IsNotNull(MemoizationCacheExtensions.ToTrimmableByArgumentAndResult <int, int>((IMemoizationCache)c));
            Assert.IsNotNull(MemoizationCacheExtensions.ToTrimmableByArgumentAndResultOrError <int, int>(c));
            Assert.IsNotNull(MemoizationCacheExtensions.ToTrimmableByArgumentAndResultOrError <int, int>((IMemoizationCache)c));
        }
        public void MemoizationCacheExtensions_ToTrimmable_HasNoService()
        {
            var c = new MyCache <int, int>(false);

            Assert.ThrowsException <InvalidOperationException>(() => MemoizationCacheExtensions.ToTrimmableByMetrics(c));
            Assert.ThrowsException <InvalidOperationException>(() => MemoizationCacheExtensions.ToTrimmableByArgumentAndResult <int, int>(c));
            Assert.ThrowsException <InvalidOperationException>(() => MemoizationCacheExtensions.ToTrimmableByArgumentAndResult <int, int>((IMemoizationCache)c));
            Assert.ThrowsException <InvalidOperationException>(() => MemoizationCacheExtensions.ToTrimmableByArgumentAndResultOrError <int, int>(c));
            Assert.ThrowsException <InvalidOperationException>(() => MemoizationCacheExtensions.ToTrimmableByArgumentAndResultOrError <int, int>((IMemoizationCache)c));
        }
        public void MemoizationCacheExtensions_AsTrimmable_HasNoService()
        {
            var c = new MyCache <int, int>(false);

            Assert.IsNull(MemoizationCacheExtensions.AsTrimmableByMetrics(c));
            Assert.IsNull(MemoizationCacheExtensions.AsTrimmableByArgumentAndResult <int, int>(c));
            Assert.IsNull(MemoizationCacheExtensions.AsTrimmableByArgumentAndResult <int, int>((IMemoizationCache)c));
            Assert.IsNull(MemoizationCacheExtensions.AsTrimmableByArgumentAndResultOrError <int, int>(c));
            Assert.IsNull(MemoizationCacheExtensions.AsTrimmableByArgumentAndResultOrError <int, int>((IMemoizationCache)c));
        }
Beispiel #16
0
        public void CachedLambdaCompiler_BigLambda()
        {
            var added = 0;

            var cache = new MyCache();

            cache.Added += () => added++;

            var rnd = new Random(1983);

            const int N = 24;
            const int M = 4;

            for (var n = 0; n < N; n++)
            {
                var ps = Enumerable.Range(0, n).Select(i => Expression.Parameter(typeof(int))).ToArray();

                for (var j = 0; j < M; j++)
                {
                    var cs = Enumerable.Range(0, n).Select(i => Expression.Constant(rnd.Next(0, 100))).ToArray();
                    var ex = ps.Zip(cs, (p, c) => (p, c)).Aggregate((Expression)Expression.Constant(42), (a, pc) => Expression.Add(a, Expression.Multiply(pc.p, pc.c)));

                    var f = Expression.Lambda(ex, ps);

                    var args = Enumerable.Range(0, n).Select(i => (object)rnd.Next(0, 100)).ToArray();

                    var d1 = f.Compile();
                    var d2 = f.Compile(cache);

                    var res1 = d1.DynamicInvoke(args);
                    var res2 = d2.DynamicInvoke(args);

                    Assert.AreEqual(res1, res2);
                }
            }

            if (Type.GetType("Mono.Runtime") == null)
            {
                Assert.AreEqual(24, added);
            }
            else
            {
                //
                // NB: Delegate caching for arities > 16 does not work on Mono. We get fresh runtime-generated delegate
                //     types every time we construct a new LambdaExpression of high arity.
                //
                //     We'll just check on upper and lower bounds for caching. In practice we've seen values of 45, but
                //     it's flaky to rely on that exact number. (45 = 17 + 4 * 7 where the latter product illustrates
                //     the lack of caching for higher arity delegates.)
                //

                Assert.IsTrue(added is >= N and < N * M);
            }
        }
Beispiel #17
0
    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        // create the empty shell
        GameObject obj = MyCache.Spawn(wpn.mShell, wpn.ShellEjector.position, wpn.ShellEjector.rotation);

        obj.GetComponent <Rigidbody>().velocity = wpn.ShellEjector.TransformDirection(Vector3.left * 8.0f);

        obj.transform.Rotate(Random.Range(-wpn.Dispersion_Y * 55.0f, wpn.Dispersion_Y * 55.0f) * Time.deltaTime,
                             Random.Range(-wpn.Dispersion_X * 55.0f, wpn.Dispersion_X * 55.0f) * Time.deltaTime, 0.0f);

        wpn.OnImpact();
    }
Beispiel #18
0
        private string GetPublishFunctionTree()
        {
            string returnValue = "";
            string cachekey    = "__bb_allfunction_treehtml";
            object o           = MyCache <string> .Get(cachekey);

            if (o != null)
            {
                returnValue = o.ToString();
            }
            else
            {
                List <FunctionEntity> list        = this.SelectAllFunctions();
                StringBuilder         sbTree_Html = new StringBuilder();
                List <FunctionEntity> k1          = list.FindAll((_k) => { return(_k.Function_Level == 1 && _k.Function_IsNew == 1 && _k.Function_isValid == 1); });
                List <FunctionEntity> k2          = list.FindAll((_k) => { return(_k.Function_Level == 2 && _k.Function_IsNew == 1 && _k.Function_isValid == 1); });

                foreach (FunctionEntity k in k1)
                {
                    sbTree_Html.Append("<li class=\"open\"><input class=\"ace-checkbox-2\" type=\"checkbox\" checktype=\"public\" onclick=\"checkchange(this);\"  level=\"");
                    sbTree_Html.Append(k.Function_Level.ToString());
                    sbTree_Html.Append("\" value=\"");
                    sbTree_Html.Append(k.Function_ID);
                    sbTree_Html.Append("\" /><span>");
                    sbTree_Html.Append(k.Function_Name);
                    sbTree_Html.Append("</span>");
                    List <FunctionEntity> thissubkinds = k2.FindAll((_k) => { return(_k.Function_ParentID == k.Function_ID); });
                    if (thissubkinds.Count > 0)
                    {
                        sbTree_Html.Append("<ul>");
                        foreach (FunctionEntity _subkind in thissubkinds)
                        {
                            sbTree_Html.Append("<li><input class=\"ace-checkbox-2\" type=\"checkbox\" checktype=\"public\" onclick=\"checkchange(this);\"  level=\"");
                            sbTree_Html.Append(_subkind.Function_Level.ToString());
                            sbTree_Html.Append("\" value=\"");
                            sbTree_Html.Append(_subkind.Function_ID);
                            sbTree_Html.Append("\" /><span>");
                            sbTree_Html.Append(_subkind.Function_Name);
                            sbTree_Html.Append("</span>");
                            sbTree_Html.Append("</li>");
                        }
                        sbTree_Html.Append("</ul>");
                    }
                    sbTree_Html.Append("</li>");
                }

                MyCache <string> .Insert(cachekey, sbTree_Html.ToString());

                returnValue = sbTree_Html.ToString();
            }

            return(returnValue);
        }
Beispiel #19
0
        public IHttpActionResult Get()
        {
            List <AppType> lat = (List <AppType>)MyCache.GetItem("apptypes");

            if (lat == null)
            {
                return(InternalServerError());
            }
            else
            {
                return(Ok(lat));
            }
        }
Beispiel #20
0
        /// <summary>
        /// 获得查询关键词使用缓存
        /// </summary>
        /// <param name="exhibitionID"></param>
        /// <returns></returns>
        public List <SearchKeyWordEntity> GetSearchKeyWordEntityListUseMyCache(int exhibitionID)
        {
            string key = string.Format(WebKeys.SearchKeyWordyCacheKey, exhibitionID.ToString());
            List <SearchKeyWordEntity> list = MyCache <List <SearchKeyWordEntity> > .Get(key);

            if (list == null)
            {
                list = this.GetSearchKeyWordEntityList(exhibitionID);
                MyCache <List <SearchKeyWordEntity> > .Insert(key, list, 600);
            }

            return(list);
        }
Beispiel #21
0
        /// <summary>
        /// 以展场id为主键,查询所有展商
        /// </summary>
        /// <param name="exhibitionID">展场id</param>
        /// <returns>展商List集合</returns>
        public List <ActivityToCustomerEntity> GetActivityEntityListUseMyCache(int exhibitionID)
        {
            string key = string.Format(WebKeys.ActivityCacheKey, exhibitionID.ToString());
            List <ActivityToCustomerEntity> list = MyCache <List <ActivityToCustomerEntity> > .Get(key);

            if (list == null)
            {
                list = this.GetActivityEntityList(exhibitionID);
                MyCache <List <ActivityToCustomerEntity> > .Insert(key, list, 600);
            }

            return(list);
        }
    public static void Main()
    {
        MyCache cache0 = new MyCache(), cache1 = new MyCache();
        string  someRandomKey = "key" + new Random().Next().ToString();

        ShowResult(cache0, cache1, someRandomKey, "Initially");
        cache0.Set(someRandomKey, Encoding.UTF8.GetBytes("hello"));
        Thread.Sleep(10);     // the pub/sub is fast, but not *instant*
        ShowResult(cache0, cache1, someRandomKey, "Write to 0");
        cache1.Set(someRandomKey, Encoding.UTF8.GetBytes("world"));
        Thread.Sleep(10);     // the pub/sub is fast, but not *instant*
        ShowResult(cache0, cache1, someRandomKey, "Write to 1");
    }
Beispiel #23
0
        public void CachedLambdaCompiler_OutliningDontDoIt_FreeVariables()
        {
            var added = 0;

            var cache = new MyCache();

            cache.Added += () => added++;

            Expression <Func <int, Func <int> > > f1 = x => () => x;
            var d1 = f1.Compile(cache, outliningEnabled: true);
            var r1 = d1(42)();

            Assert.AreEqual(42, r1);
            Assert.AreEqual(1, added);
        }
Beispiel #24
0
        public void CachedLambdaCompiler_OutliningDontDoIt_Quote()
        {
            var added = 0;

            var cache = new MyCache();

            cache.Added += () => added++;

            Expression <Func <IQueryable <int>, IQueryable <int> > > f1 = xs => xs.Where(x => x > 1).Select(x => x * 2);
            var d1 = f1.Compile(cache, outliningEnabled: true);
            var r1 = d1(new[] { 1, 2, 3, 4 }.AsQueryable());

            Assert.IsTrue(new[] { 4, 6, 8 }.SequenceEqual(r1));
            Assert.AreEqual(1, added);
        }
Beispiel #25
0
        /// <summary>
        /// 设定绝对的过期时间
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <param name="objObject"></param>
        /// <param name="seconds">超过多少秒后过期</param>
        private void SetAbsoluteExpirationCache(string CacheKey, object obj, int seconds)
        {
            MyCache <string> .Insert(CacheKey, "1", seconds / 5);

            //Cache objCache = HttpRuntime.Cache;
            //if (objCache.Get(cacheTimeoutName) == null)
            //{
            //    lock (cacheobj)
            //    {
            //         if (objCache.Get(cacheTimeoutName) == null)
            //         {
            //             objCache.Insert(CacheKey, obj, null, System.DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero);
            //         }
            //    }
            //}
        }
Beispiel #26
0
        public void CachedLambdaCompiler_CustomHoister2()
        {
#pragma warning disable IDE0034 // Simplify 'default' expression (illustrative of method signature)
            var h = ConstantHoister.Create(false,
                                           (Expression <Func <string, string> >)(s => string.Format(s, default(object[])))
                                           );
#pragma warning restore IDE0034 // Simplify 'default' expression

            foreach (var outline in new[] { false, true })
            {
                var added = 0;

                var cache = new MyCache();
                cache.Added += () => added++;

                Expression <Func <int, string> > f1 = x => string.Format("{0}:{1}", new object[] { x, 43 });
                Expression <Func <int, string> > f2 = x => string.Format("{0}:{1}", new object[] { x, 44 });
                Expression <Func <int, string> > f3 = x => string.Format("{1}:{0}", new object[] { x, 45 });

                for (var i = 0; i < 2; i++)
                {
                    var d1 = ((LambdaExpression)f1).Compile(cache, outline, h);
                    var r1 = d1.DynamicInvoke(42);

                    Assert.AreEqual("42:43", r1);
                    Assert.AreEqual(1, added);
                }

                for (var i = 0; i < 2; i++)
                {
                    var d2 = ((LambdaExpression)f2).Compile(cache, outline, h);
                    var r2 = d2.DynamicInvoke(42);

                    Assert.AreEqual("42:44", r2);
                    Assert.AreEqual(1, added);
                }

                for (var i = 0; i < 2; i++)
                {
                    var d3 = ((LambdaExpression)f3).Compile(cache, outline, h);
                    var r3 = d3.DynamicInvoke(42);

                    Assert.AreEqual("45:42", r3);
                    Assert.AreEqual(2, added);
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// 得到春联  使用缓存
        /// </summary>
        /// <param name="isReload"></param>
        /// <returns></returns>
        public List <CoupletGroupEntity> GetCoupletGroupEntityListWithCache(bool isReload = false)
        {
            string key = WebKeys.CoupletCacheKey;
            List <CoupletGroupEntity> list = null;

            if (!isReload)
            {
                list = MyCache <List <CoupletGroupEntity> > .Get(key);
            }
            if (list == null)
            {
                list = this.GetCoupletGroupEntityList();
                MyCache <List <CoupletGroupEntity> > .Insert(key, list, 60);
            }

            return(list);
        }
Beispiel #28
0
    /*
     *  private void ChangeDispersionSize()
     *  {
     *          DispersionTime += Time.deltaTime;
     *          if ( DispersionTime > 0.8f )
     *          {
     *                  DispersionSize -= DecDispersionSize;
     *
     *                  if ( DispersionSize < 0.12 )
     *                  {
     *                          DSDefault = true;
     *                          DispersionTime = 0f;
     *                  }
     *          }
     *  }
     */
    #endregion

    #region Messages
    public void OnImpact()
    {
        RaycastHit hit;
        var        ray = new Ray(transform.position, transform.forward);

        if (Physics.Raycast(ray, out hit, Range))
        {
            var effect = ImpactManager.Instance.GetImpactEffect(hit.transform.gameObject);
            if (effect == null)
            {
                return;
            }
            var effectIstance = MyCache.Spawn(effect, hit.point, new Quaternion()) as GameObject;
            effectIstance.transform.LookAt(hit.point + hit.normal);
            //  MyCache.Destroy(effectIstance, 4); // de-activate after 4 secs
        }
    }
Beispiel #29
0
        /// <summary>
        /// 得到春联  使用缓存
        /// </summary>
        /// <param name="isReload"></param>
        /// <returns></returns>
        public List <FuImageEntity> GetFuImageEntityListWithCache(bool isReload = false)
        {
            string key = WebKeys.FuimageCacheKey;
            List <FuImageEntity> list = null;

            if (!isReload)
            {
                list = MyCache <List <FuImageEntity> > .Get(key);
            }
            if (list == null)
            {
                list = this.GetFuImageList();
                MyCache <List <FuImageEntity> > .Insert(key, list, 60);
            }

            return(list);
        }
Beispiel #30
0
        /// <summary>
        /// 判断邮件缓存名是否过期
        /// 没过期 邮件线程不操作数据库继续休眠
        /// 过期 邮件线程开始尝试从数据库读取未发邮件
        /// </summary>
        /// <returns></returns>
        private bool IsExistsMailCacheName(bool w = true)
        {
            return(!string.IsNullOrEmpty(MyCache <string> .Get(cacheTimeoutName)));

            //Cache objCache = HttpRuntime.Cache;
            //if (objCache.Get(cacheTimeoutName) != null)
            //{
            //    lock (cacheobj2)
            //    {
            //          if (objCache.Get(cacheTimeoutName) != null)
            //          {
            //              return true;
            //          }
            //    }
            //}
            //return false;
        }
Beispiel #31
0
        public void TestCache()
        {
            var storage1 = new MyCache <int, string>();

            var containsBefore1 = storage1.Contains(1);

            storage1.Upsert(1, "value1");
            var containsAfter1 = storage1.Contains(1);
            var value1         = storage1.Get(1);

            var storage2 = new MyCache <int, string>();

            var containsBefore2 = storage2.Contains(1);

            storage2.Upsert(1, "value2");
            var containsAfter2 = storage2.Contains(1);
            var value2         = storage2.Get(1);
        }