示例#1
0
        private void SetupRegion(uint entryTTL, uint entryIdleTimeout,
                                 uint regionTTL, uint regionIdleTimeout)
        {
            const ExpirationAction action = ExpirationAction.Destroy;

            RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);

            rf.SetEntryTimeToLive(action, entryTTL);
            rf.SetEntryIdleTimeout(action, entryIdleTimeout);
            rf.SetRegionTimeToLive(action, regionTTL);
            rf.SetRegionIdleTimeout(action, regionIdleTimeout);

            CacheHelper.Init();
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>(m_regionName);

            if ((region != null) && !region.IsDestroyed)
            {
                region.GetLocalView().DestroyRegion();
                Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> {0} was not destroyed.", m_regionName);
            }
            m_region = rf.Create <object, object>(m_regionName);
            Assert.IsNotNull(m_region, "IRegion<object, object> was not created.");
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache Programmatically.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
                Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                            .Create();

                Console.WriteLine("Created the Geode Cache");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                // Create the example Region programmatically.
                IRegion <string, string> region = regionFactory
                                                  .SetEntryIdleTimeout(ExpirationAction.Destroy, 10)
                                                  .Create <string, string>("exampleRegion");

                Console.WriteLine("Created the Region with generics support programmatically.");

                // Plugin the SimpleCacheListener to the Region.
                AttributesMutator <string, string> attrMutator = region.AttributesMutator;
                attrMutator.SetCacheListener(new SimpleCacheListener <string, string>());

                Console.WriteLine("Set the generic SimpleCacheListener on the Region");

                // Put 3 Entries into the Region using the IDictionary interface.
                region["Key1"] = "Value1";
                region["Key2"] = "Value2";
                region["Key3"] = "Value3";

                Console.WriteLine("Put 3 Entries into the Region");

                // Get the Entry Idle Timeout specified in the Cache XML file.
                int entryIdleTimeout = region.Attributes.EntryIdleTimeout;

                Console.WriteLine("Got Entry Idle Timeout as {0} seconds", entryIdleTimeout);

                // Wait for half the Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000 / 2);

                // Get the number of Keys remaining in the Region, should be all 3.
                ICollection <string> keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys before the Entry Idle Timeout duration elapsed", keys.Count);

                // Get 2 of the 3 Entries from the Region to "reset" their Idle Timeouts.
                string value1 = region["Key1"];
                string value2 = region["Key2"];

                Console.WriteLine("The SimpleCacheListener should next report the expiration action");

                // Wait for the entire Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000);

                // Get the number of Keys remaining in the Region, should be 0 now.
                keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys after the Entry Idle Timeout duration elapsed", keys.Count);

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("DataExpiration Geode Exception: {0}", gfex.Message);
            }
        }