예제 #1
0
        public static void Init(Container container)
        {
            ICacheLoader cacheLoader = container.GetInstance <ICacheLoader>();

            cacheLoader.Init();
            cacheLoader.Refresh();
        }
예제 #2
0
        private void SetCacheLoader(string regionName, ICacheLoader <string, string> loader)
        {
            GIRegion region = CacheHelper.GetVerifyRegion <string, string>(regionName);
            AttributesMutator <string, string> attrMutator = region.AttributesMutator;

            attrMutator.SetCacheLoader(loader);
        }
예제 #3
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (_cacheLoader != null)
     {
         _cacheLoader.Dispose();
         _cacheLoader = null;
     }
     if (_task != null && _task.IsAlive)
     {
         _task.Abort();
     }
 }
예제 #4
0
        /// <summary>
        /// Retrieves the value for key requested. If the key does not exist
        /// in the cache then the Fetch method is used to retrieve the value
        /// from another source.
        /// </summary>
        /// <param name="key">Key for the item required</param>
        /// <param name="loader">Loader to fetch the item from if not in the cache</param>
        /// <returns>An instance of the value associated with the key</returns>
        internal V this[K key, ICacheLoader <K, V> loader]
        {
            get
            {
                bool added = false;
                Interlocked.Increment(ref _requests);
                LinkedListNode <KeyValuePair <K, V> > node, newNode = null;
                if (_dictionary.TryGetValue(key, out node) == false)
                {
                    // Get the item fresh from the loader before trying
                    // to write the item to the cache.
                    Interlocked.Increment(ref _misses);
                    newNode = new LinkedListNode <KeyValuePair <K, V> >(
                        new KeyValuePair <K, V>(key, loader.Fetch(key)));

                    lock (_writeLock)
                    {
                        // If the node has already been added to the dictionary
                        // then get it, otherwise add the one just fetched.
                        node = _dictionary.GetOrAdd(key, newNode);

                        // If the node got from the dictionary is the new one
                        // just fetched then it needs to be added to the linked
                        // list.
                        if (node == newNode)
                        {
                            added = true;
                            _linkedList.AddFirst(node);

                            // Check to see if the cache has grown and if so remove
                            // the last element.
                            RemoveLeastRecent();
                        }
                    }
                }

                // The item is in the dictionary. Check it's still in the list
                // and if so them move it to the head of the linked list.
                if (added == false)
                {
                    lock (_writeLock)
                    {
                        if (node.List != null)
                        {
                            _linkedList.Remove(node);
                            _linkedList.AddFirst(node);
                        }
                    }
                }
                return(node.Value.Value);
            }
        }
예제 #5
0
        public FeederBootstrapper()
        {
            Container container = new Container();

            container.Options.DefaultLifestyle = Lifestyle.Singleton;

            InitializeDependencies(container);
            InitializeDb(container);
            InitializeMapping();

            this.cacheLoader = container.GetInstance <ICacheLoader>();
            this.cacheLoader.Init();

            this.synchronizer = container.GetInstance <ISynchronizer>();
        }
예제 #6
0
        /// <summary>
        /// 从继承的CustomerLoader中获取数据
        /// </summary>
        /// <param name="entityCfg"></param>
        /// <returns></returns>
        private IList loadCacheData(EntityCfg entityCfg)
        {
            IList data;

            if (!string.IsNullOrEmpty(entityCfg.CustomLoaderType))
            {
                string[]     cfgContent  = entityCfg.CustomLoaderType.Split(',');
                ICacheLoader cacheLoader = MB.Util.DllFactory.Instance.LoadObject(cfgContent[0].Trim(), cfgContent[1].Trim()) as ICacheLoader;
                data = cacheLoader.LoadCache();
            }
            else
            {
                throw new MB.Util.APPException("Entity节点中CustomLoaderType不存在");
            }

            return(data);
        }
 public CardLoaderAddLinkedFaceCardDecorator(ICacheLoader <Dictionary <int, Card> > decoratee)
 {
     this.decoratee = decoratee;
 }
예제 #8
0
 /// <summary>
 /// Configura a instancia com o CacheLoader informado.
 /// </summary>
 /// <param name="cacheLoader"></param>
 public void Initialize(ICacheLoader cacheLoader)
 {
     _cacheLoader = cacheLoader;
 }
예제 #9
0
 /// <summary>
 /// Inicializa a instancia com as propriedades informadas.
 /// </summary>
 /// <param name="properties"></param>
 private void Initialize(IDictionary properties)
 {
     properties.Require("properties").NotNull();
     try
     {
         if (!properties.Contains("assembly"))
         {
             throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_MissingAssemblyName).Format());
         }
         if (!properties.Contains("classname"))
         {
             throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_MissingClassName).Format());
         }
         var    assemblyName = Convert.ToString(properties["assembly"]);
         string typeName     = Convert.ToString(properties["classname"]);
         string path         = Convert.ToString(properties["full-name"]);
         string extension    = ".dll";
         if (properties.Contains("full-name"))
         {
             extension = System.IO.Path.GetExtension(path);
         }
         IDictionary parameters = properties["parameters"] as IDictionary;
         if (parameters == null)
         {
             parameters = new Hashtable();
         }
         try
         {
             if (!string.IsNullOrEmpty(path) && extension.EndsWith(".dll") || extension.EndsWith(".exe"))
             {
                 System.Reflection.Assembly assembly = null;
                 string assemblyFile = CachingUtils.DeployedAssemblyDir + _cache.Name + @"\" + path;
                 try
                 {
                     assembly = System.Reflection.Assembly.LoadFrom(assemblyFile);
                 }
                 catch (Exception exception)
                 {
                     throw new Exception(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.Exception_CouldNotLoadAssembly, assemblyFile, exception.Message).Format());
                 }
                 if (assembly != null)
                 {
                     _cacheLoader = (ICacheLoader)assembly.CreateInstance(typeName);
                 }
             }
             else
             {
                 var type = Type.GetType(string.Format("{0}, {1}", typeName, assemblyName), false);
                 if (type != null)
                 {
                     _cacheLoader = (ICacheLoader)Activator.CreateInstance(type);
                 }
             }
             if (_cacheLoader == null)
             {
                 throw new Exception(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.Exception_UnableToInstantiate, typeName).Format());
             }
             _cacheLoader.Init(parameters);
         }
         catch (InvalidCastException)
         {
             throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_ICacheLoaderNotImplemented).Format());
         }
         catch (Exception exception2)
         {
             throw new ConfigurationException(exception2.Message, exception2);
         }
     }
     catch (ConfigurationException)
     {
         throw;
     }
     catch (Exception exception3)
     {
         throw new ConfigurationException("Configuration Error: " + exception3.ToString(), exception3);
     }
 }
예제 #10
0
 /// <summary>
 /// Constructs a new instance of <see cref="Cache{T}"/> for
 /// use with entities.
 /// </summary>
 /// <param name="cacheSize">
 /// The number of items to store in the cache.
 /// </param>
 /// <param name="loader">
 /// Loader used to fetch items not in the cache.
 /// </param>
 internal Cache(int cacheSize, ICacheLoader <int, T> loader) : base(cacheSize, loader)
 {
 }
        public MainWindowVM(StatusBlinker statusBlinker, InMatchTrackerStateVM inMatchState, ConfigModel config, DraftingVM draftingVM,
                            IMapper mapper,
                            ICacheLoader <Dictionary <int, Set> > cacheSets,
                            ProcessMonitor processMonitor,
                            ServerApiCaller api,
                            StartupShortcutManager startupManager,
                            MtgaResourcesLocator resourcesLocator,
                            FileMonitor fileMonitor,
                            DraftCardsPicker draftHelper,
                            ReaderMtgaOutputLog readerMtgaOutputLog,
                            InGameTracker2 inMatchTracker,
                            ExternalProviderTokenManager tokenManager,
                            PasswordHasher passwordHasher,
                            CacheSingleton <Dictionary <string, DraftRatings> > draftRatings,
                            DraftHelperRunner draftHelperRunner,
                            //IEmailProvider emailProvider,
                            ICollection <Card> allCards,
                            CardThumbnailDownloader cardThumbnailDownloader,
                            ServerApiCaller serverApiCaller
                            )
        {
            // Set the status blinker reference
            StatusBlinker = statusBlinker;
            // Set the network status emission handler
            StatusBlinker.EmitStatus += status => { NetworkStatus = status; };

            Sets                               = cacheSets.LoadData().Values.ToArray();
            InMatchState                       = inMatchState;
            Config                             = config;
            DraftingVM                         = draftingVM;
            Mapper                             = mapper;
            ProcessMonitor                     = processMonitor;
            Api                                = api;
            StartupManager                     = startupManager;
            ResourcesLocator                   = resourcesLocator;
            FileMonitor                        = fileMonitor;
            DraftHelper                        = draftHelper;
            ReaderMtgaOutputLog                = readerMtgaOutputLog;
            InMatchTracker                     = inMatchTracker;
            InMatchState.GameEnded            += OnGameEnded;
            InMatchState.OpponentCardsUpdated += OnOpponentCardsUpdated;

            TokenManager      = tokenManager;
            PasswordHasher    = passwordHasher;
            DraftRatings      = draftRatings;
            DraftHelperRunner = draftHelperRunner;
            //this.emailProvider = emailProvider;
            AllCards = allCards;
            CardThumbnailDownloader = cardThumbnailDownloader;
            this.serverApiCaller    = serverApiCaller;

            // Set the library order from the config
            OrderLibraryCardsBy = config.OrderLibraryCardsBy == "Converted Mana Cost"
                ? CardsListOrder.ManaCost
                : CardsListOrder.DrawChance;

            // Create the opponent window view model
            OpponentWindowVM = new OpponentWindowVM("Opponent Cards", this, serverApiCaller);

            // Subscribe to property changes
            PropertyChanged += OnPropertyChanged;

            // Set the animated icon state
            AnimatedIcon = Config?.AnimatedIcon ?? false;

            // Set the initial window settings
            PositionTop   = WindowSettings?.Position.Y ?? 0;
            PositionLeft  = WindowSettings?.Position.X ?? 0;
            WindowOpacity = WindowSettings?.Opacity ?? 0.9;
            WindowTopmost = WindowSettings?.Topmost ?? true;

            // Set the initial window size
            WindowWidth = WindowSettings != null && WindowSettings.Size.X > double.Epsilon
                ? WindowSettings.Size.X
                : 340;
            WindowHeight = WindowSettings != null && WindowSettings.Size.Y > double.Epsilon
                ? WindowSettings.Size.Y
                : 500;
        }
 public CacheSingleton(ICacheLoader <T> loader)
 {
     this.loader = loader;
 }
예제 #13
0
        public void TestLocalNamedCacheInstancing()
        {
            IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory;

            IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml");

            ccf.Config = config;

            INamedCache cache1 = ccf.EnsureCache("local-default");

            Assert.IsNotNull(cache1);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            LocalNamedCache lnc = cache1 as LocalNamedCache;

            Assert.IsNotNull(lnc);
            LocalCache lc1 = lnc.LocalCache;

            Assert.AreEqual(lc1.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc1.FlushDelay, 0);
            Assert.AreEqual(lc1.HighUnits, LocalCache.DEFAULT_UNITS);
            Assert.AreEqual(lc1.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc1.EvictionType, LocalCache.EvictionPolicyType.Hybrid);

            INamedCache cache2 = ccf.EnsureCache("local-with-init");

            Assert.IsNotNull(cache2);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache1);
            lnc = cache2 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc2 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, 10);
            Assert.AreEqual(lc2.FlushDelay, 1000);
            Assert.AreEqual(lc2.HighUnits, 32000);
            Assert.AreEqual(lc2.LowUnits, 10);
            Assert.AreEqual(lc2.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc2.EvictionType, LocalCache.EvictionPolicyType.LRU);
            Assert.IsNotNull(lc2.CacheLoader);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), lc2.CacheLoader);

            INamedCache cache3 = ccf.EnsureCache("local-custom-impl");

            Assert.IsNotNull(cache3);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache3);

            INamedCache cache4 = ccf.EnsureCache("local-custom-impl-with-init");

            Assert.IsNotNull(cache4);
            Assert.IsInstanceOf(typeof(TestLocalNamedCache), cache4);
            TestLocalNamedCache tlnc = cache4 as TestLocalNamedCache;

            Assert.IsNotNull(tlnc);
            LocalCache lc4 = tlnc.LocalCache;

            Assert.AreEqual(lc4.ExpiryDelay, 60000);
            Assert.AreEqual(lc4.FlushDelay, 1000);
            Assert.AreEqual(lc4.HighUnits, 32000);
            Assert.AreEqual(lc4.LowUnits, 10);
            Assert.AreEqual(lc4.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc4.EvictionType, LocalCache.EvictionPolicyType.LFU);

            INamedCache cache5 = ccf.EnsureCache("local-ref");

            Assert.IsNotNull(cache5);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache5);
            lnc = cache5 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc5 = lnc.LocalCache;

            Assert.AreEqual(lc2.ExpiryDelay, lc5.ExpiryDelay);
            Assert.AreEqual(lc2.FlushDelay, lc5.FlushDelay);
            Assert.AreEqual(lc2.HighUnits, lc5.HighUnits);
            Assert.AreEqual(lc2.CalculatorType, lc5.CalculatorType);
            Assert.AreEqual(lc2.EvictionType, lc5.EvictionType);

            Assert.IsInstanceOf(typeof(DefaultConfigurableCacheFactory), ccf);
            DefaultConfigurableCacheFactory dccf = ccf as DefaultConfigurableCacheFactory;

            Assert.IsNotNull(dccf);
            DefaultConfigurableCacheFactory.CacheInfo ci = dccf.FindSchemeMapping("local-override-params");
            Assert.IsNotNull(ci);
            Assert.AreEqual(ci.CacheName, "local-override-params");
            Assert.AreEqual(ci.SchemeName, "example-local-7");
            IDictionary attrs = ci.Attributes;

            Assert.IsNotNull(attrs);
            Assert.AreEqual(attrs.Count, 1);
            Assert.IsTrue(attrs.Contains("LowUnits10"));

            INamedCache cache6 = ccf.EnsureCache("local-override-params");

            Assert.IsNotNull(cache6);
            Assert.IsInstanceOf(typeof(LocalNamedCache), cache6);
            lnc = cache6 as LocalNamedCache;
            Assert.IsNotNull(lnc);
            LocalCache lc6 = lnc.LocalCache;

            Assert.AreEqual(lc6.ExpiryDelay, LocalCache.DEFAULT_EXPIRE);
            Assert.AreEqual(lc6.FlushDelay, 0);
            Assert.AreEqual(lc6.HighUnits, 100);
            Assert.AreEqual(lc6.LowUnits, 10);
            Assert.AreEqual(lc6.CalculatorType, LocalCache.UnitCalculatorType.Fixed);
            Assert.AreEqual(lc6.EvictionType, LocalCache.EvictionPolicyType.LFU);

            Assert.IsNotNull(lc6.CacheLoader);
            ICacheLoader cl         = lc6.CacheLoader;
            TestLoader   testLoader = cl as TestLoader;

            Assert.IsNotNull(testLoader);
            Assert.AreEqual(testLoader.StringProperty, ci.CacheName);
            Assert.AreEqual(testLoader.IntProperty, 10);
            Assert.IsTrue(testLoader.BoolProperty);
            INamedCache c = testLoader.CacheProperty;

            Assert.IsNotNull(c);
            Assert.IsInstanceOf(typeof(LocalNamedCache), c);

            Assert.IsTrue(cache1.IsActive);
            Assert.IsTrue(cache2.IsActive);
            Assert.IsTrue(cache3.IsActive);
            Assert.IsTrue(cache4.IsActive);
            Assert.IsTrue(cache5.IsActive);
            Assert.IsTrue(cache6.IsActive);

            CacheFactory.Shutdown();

            Assert.IsFalse(cache1.IsActive);
            Assert.IsFalse(cache2.IsActive);
            Assert.IsFalse(cache3.IsActive);
            Assert.IsFalse(cache4.IsActive);
            Assert.IsFalse(cache5.IsActive);
            Assert.IsFalse(cache6.IsActive);
        }
 /// <summary>
 /// Construct the LocalNamedCache.
 /// </summary>
 /// <param name="units">
 /// The number of units that the underlying <b>LocalCache</b> will
 /// cache before pruning the cache.
 /// </param>
 /// <param name="expiryMillis">
 /// The number of milliseconds that each cache entry lives before
 /// being automatically expired.
 /// </param>
 /// <param name="loader">
 /// The <see cref="ICacheLoader"/> or <see cref="ICacheStore"/> to
 /// use.
 /// </param>
 public LocalNamedCache(int units, int expiryMillis, ICacheLoader loader)
 {
     m_localCache = new LocalCache(units, expiryMillis, loader);
 }
예제 #15
0
 /// <summary>
 /// Constructs a new instance of the cache.
 /// </summary>
 /// <param name="cacheSize">The number of items to store in the cache</param>
 /// <param name="loader">Loader used to fetch items not in the cache</param>
 internal Cache(int cacheSize, ICacheLoader <K, V> loader) : this(cacheSize)
 {
     _loader = loader;
 }