示例#1
0
        public void IsThreadSafe()
        {
            var reads = 0;
            var cache = new BytesCache();

            Parallel.For(0, 64, (idx) =>
            {
                cache.Content("test", () => new byte[1] {
                    0xAA
                });
                cache.Update("test",
                             () => { reads++; return(new byte[1] {
                        0xBB
                    }); },
                             () => { reads++; return(new byte[1] {
                        0xCC
                    }); }
                             );

                cache.Content("test", () => { reads++; return(new byte[1] {
                        0xDD
                    }); });
            });

            Assert.Equal(64, reads);
        }
示例#2
0
        public void CachesOnUpdate()
        {
            var reads = 0;
            var cache = new BytesCache();

            cache.Content("test", () => new byte[1] {
                0xAA
            });
            cache.Update("test",
                         () => { reads++; return(new byte[1] {
                    0xBB
                }); },
                         () => { reads++; return(new byte[1] {
                    0xCC
                }); }
                         );

            cache.Content("test", () => { reads++; return(new byte[1] {
                    0xDD
                }); });

            Assert.Equal(1, reads);
        }