public LocationController(IRequestHandler <LocationViewModel> requestHandler, ICacheController cache, IMemoryCache memoryCache) { _controllerHelper = new RequestControllerHelper(); _requestHandler = requestHandler; _cache = cache; _memoryCache = memoryCache; }
static void Main(string[] args) { ICacheController <int> cacheController = CreateController(); // write -> read byte[] bytes42 = Encoding.ASCII.GetBytes("first42"); byte[] bytes43 = Encoding.ASCII.GetBytes("first43"); Word word42 = new Word(42, bytes42); Word word43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBack42 = cacheController.ReadWord(42); cacheController.WriteWord(43, word43); Word wordBack43 = cacheController.ReadWord(43); // update -> read byte[] byteSecond42 = Encoding.ASCII.GetBytes("second42"); byte[] byteSecond43 = Encoding.ASCII.GetBytes("second43"); Word wordSecond42 = new Word(42, bytes42); Word wordSecond43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBackSecond42 = cacheController.ReadWord(42); cacheController.WriteWord(43, word43); Word wordBackSecond43 = cacheController.ReadWord(43); }
public void WriteWordTest2_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { // write -> read string s = string.Format("1st{0:000}", i); Word word = new Word(i, Convert(s)); cacheController.WriteWord(i, word); Word wordBack = cacheController.ReadWord(i); Assert.AreEqual(word.Tag, wordBack.Tag); Assert.IsTrue(word.Buffer.SequenceEqual(wordBack.Buffer)); // update -> read s = string.Format("2nd{0:000}", i); Word wordSecond = new Word(i, Convert(s)); cacheController.WriteWord(i, wordSecond); Word wordBackSecond = cacheController.ReadWord(i); Assert.AreEqual(wordSecond.Tag, wordBackSecond.Tag); } while (!databaseStorage_.EOF(++i)); }
public void ReadWordTest3_Sequential() { ICacheController <int> cacheController = CreateController(); // if line consists from n words then word0...wordn-1 will be not chached when word0 requested first time // but subsequent reading of word1..wordn-1 will hit for (int i = kMinSequentialUserID; i <= kMaxSequentialUserID; ++i) { Word word = cacheController.ReadWord(i); if (i % kWordsInLine == 1) { Assert.AreEqual(word.isCached, false); // miss for word0 } else { Assert.AreEqual(word.isCached, true); // hit for word1..wordn-1 } } Word word291 = cacheController.ReadWord(291); Assert.IsTrue(word291.IsEmpty); Word word999 = cacheController.ReadWord(999); Assert.AreEqual(word999.isCached, true); }
/// <summary> /// Initializes a new instance of the <see cref="ParseCurrentConfigurationController"/> class. /// </summary> public ParseCurrentConfigurationController(ICacheController storageController, IParseDataDecoder decoder) { StorageController = storageController; Decoder = decoder; TaskQueue = new TaskQueue { }; }
public void Initialize() { this._flushInterval.Initialize(); try { if (this._implementation == null) { throw new DataMapperException("Error instantiating cache controller for cache named '" + this._id + "'. Cause: The class for name '" + this._implementation + "' could not be found."); } Type type = TypeUtils.ResolveType(this._implementation); object[] args = new object[0]; this._controller = (ICacheController)Activator.CreateInstance(type, args); } catch (Exception exception) { throw new ConfigurationException("Error instantiating cache controller for cache named '" + this._id + ". Cause: " + exception.Message, exception); } try { this._controller.Configure(this._properties); } catch (Exception exception2) { throw new ConfigurationException("Error configuring controller named '" + this._id + "'. Cause: " + exception2.Message, exception2); } }
public void ReadWordTest4_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { Word word = cacheController.ReadWord(i); if (word.IsEmpty) { continue; } if (i % kWordsInLine == 1) { Assert.AreEqual(word.isCached, false); // miss word = cacheController.ReadWord(i); Assert.AreEqual(word.isCached, true); // hit second time } else { Assert.AreEqual(word.isCached, true); // hit } } while (!databaseStorage_.EOF(++i)); }
static SlimCacheManager() { _StaticCacheController = CacheControllerFactory.CreateCacheController(); _Cache = MemoryCache.Default; CacheItemContainer container; foreach (ICacheItem item in _StaticCacheController.IterateOverCacheItems()) { // get the global cachesettings if (item.LifeSpan.TotalMilliseconds <= 0) { item.LifeSpan = _StaticCacheController.LifeSpanInterval; } if (item.LifeSpan == TimeSpan.Zero) { throw new CachingException("Cache Configuration item with key " + item.Name + " has no expiry time specified. Either set the Seconds or Minutes value. It is allowed to set both values at a time."); } container = new CacheItemContainer( item , string.IsNullOrEmpty(item.CacheKey) ? item.Name : item.CacheKey); ContinuousCacheAccessSynchronizationManager.InitializeCacheItemSynchronizationController(container); } }
/// <summary> /// /// </summary> public void Initialize() { // Initialize FlushInterval _flushInterval.Initialize(); try { if (_implementation == null) { throw new DataMapperException("Error instantiating cache controller for cache named '" + _id + "'. Cause: The class for name '" + _implementation + "' could not be found."); } // Build the CacheController Type type = TypeUtils.ResolveType(_implementation); object[] arguments = new object[0]; _controller = (ICacheController)Activator.CreateInstance(type, arguments); } catch (Exception e) { throw new ConfigurationException("Error instantiating cache controller for cache named '" + _id + ". Cause: " + e.Message, e); } //------------ configure Controller--------------------- try { _controller.Configure(_properties); } catch (Exception e) { throw new ConfigurationException("Error configuring controller named '" + _id + "'. Cause: " + e.Message, e); } }
public AccountController(IRequestHandler <UserViewModel> requestHandler, ICacheController cache, IMemoryCache memoryCache) { _requestHandler = requestHandler; _cache = cache; _memoryCache = memoryCache; _controllerHelper = new RequestControllerHelper(); }
public ParseCurrentInstallationController(IParseInstallationController installationIdController, ICacheController storageController, IParseInstallationCoder installationCoder, IParseObjectClassController classController) { InstallationController = installationIdController; StorageController = storageController; InstallationCoder = installationCoder; ClassController = classController; }
public IInventoryServiceBuilder SetCachingService(ICacheController cacheController = null) { if (cacheController != null) { this.cacheStrategy = cacheController; } return(this); }
public static ICacheController <Tag> Create(CacheGeometry cacheGeometry , IStorage <Tag> storage , IReplacementStrategy <Tag> replacementStrategy) { ICacheController <Tag> cacheController = Create(cacheGeometry, storage); cacheController.ReplacementStrategy = replacementStrategy; return(cacheController); }
/// <summary> /// Adds a Cache Data object to the Controller and returns a CacheDataController /// </summary> /// <param name="controller">Cache Controller that will manage this the Cache Data</param> /// <param name="type">Class type that implements ICacheData</param> public static CacheDataController CreateCacheData(ICacheController controller, Type type) { var data = (ICacheData)Activator.CreateInstance(type); var dataController = new CacheDataController(); dataController.Initialize(data); controller.Add(dataController); return(dataController); }
public InventoryService(ICacheController cacheStrategy, IDictionary <string, Queue <IItem> > dictionary, IInventoryState state) { if (dictionary == null) { throw new ArgumentNullException(nameof(dictionary)); } this.cacheStrategy = cacheStrategy; this.itemDictonary = new ReadOnlyDictionary <string, Queue <IItem> >(dictionary); this.InventoryState = state; }
public void PostConstruct(params object[] args) { if (!_sceneReferenceProvider.TryGetEntry(Tags.PowerupCache, out var powerupCache)) { Debug.LogError($"[{nameof(PowerupMovement)}] Cannot find references"); return; } _cacheController = new PowerupCacheController(powerupCache.transform, Camera.main.transform.position); Reset(); }
public void TestFlush() { ICacheController cc = GetController(); string testKey = "testKey"; string testVal = "testVal"; Assert.AreEqual(cc[testKey], null); cc[testKey] = testVal; Assert.AreEqual(cc[testKey], testVal); cc.Flush(); Assert.AreEqual(cc[testKey], null); }
public void TestRemoveObject() { ICacheController cc = GetController(); string testKey = "testKey"; string testVal = "testVal"; Assert.AreEqual(cc[testKey], null); cc[testKey] = testVal; Assert.AreEqual(cc[testKey], testVal); cc.Remove(testKey); Assert.AreEqual(cc[testKey], null); }
public void TestGetAndPutObject() { ICacheController cc = GetController(); string testKey = "testKey"; string testVal = "testVal"; Assert.AreEqual(cc[testKey], null); cc[testKey] = testVal; Assert.AreEqual(cc[testKey], testVal); cc[testKey] = null; Assert.AreEqual(cc[testKey], null); }
protected override ICacheController <int> CreateController() { databaseStorage_ = new DatabaseStorageMock <int, string>(); FillDatabaseTest(); CacheGeometry cacheGeometry = new CacheGeometry(numberOfWays: kNumberOfWays , linesDegree: kLinesDegree , wordsInLine: kWordsInLine , wordSize: kWordSize , 2); IReplacementStrategy <int> replacementStrategy = new LRUStrategy <int>(cacheGeometry); ICacheController <int> cacheController = CacheFactory <int> .Create(cacheGeometry, databaseStorage_, replacementStrategy); return(cacheController); }
/// <summary> /// Gets the Cache section settings of the app.config /// </summary> public static ICacheController CreateCacheController() { CacheSection section = (CacheSection)ConfigurationManager.GetSection(SECTION_NAME); if (!string.IsNullOrEmpty(section.CacheControllerType)) { ICacheController customController = Activator.CreateInstance(Type.GetType(section.CacheControllerType)) as ICacheController; if (customController != null) { return(customController.CreateCacheControllerInstance()); } } return(section); }
static ICacheController <int> CreateController() { databaseStorage_.database_.Clear(); FillDatabaseTest(); CacheGeometry cacheGeometry = new CacheGeometry(numberOfWays: kNumberOfWays , linesDegree: kLinesDegree , wordsInLine: kWordsInLine , wordSize: kWordSize , 2); IReplacementStrategy <int> replacementStrategy = new LRUStrategy <int>(cacheGeometry); ICacheController <int> cacheController = CacheFactory <int> .Create(cacheGeometry, databaseStorage_, replacementStrategy); return(cacheController); }
public void ReadWordTest1_SelectedTags() { ICacheController <int> cacheController = CreateController(); Word word42 = cacheController.ReadWord(42); Word word42Hit = cacheController.ReadWord(42); // read hit Assert.AreEqual(word42.Tag, word42Hit.Tag); Assert.AreEqual(word42Hit.isCached, true); Word word = cacheController.ReadWord(43); Word wordHit = cacheController.ReadWord(43); // read hit Assert.AreEqual(word.Tag, wordHit.Tag); Assert.AreEqual(wordHit.isCached, true); }
public void ReadWordTest2_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { Word word = cacheController.ReadWord(i); Word wordHit = cacheController.ReadWord(i); // read hit second time for the same word if (!wordHit.IsEmpty) { Assert.AreEqual(word.Tag, wordHit.Tag); } } while (!databaseStorage_.EOF(++i)); }
public CachedElement(ICacheItem item, ICacheController controller) { this._CacheItemPriority = item.CacheItemPriority; this._Enabled = item.Enabled; this._IsIterating = item.IsIterating; this._Minutes = item.Minutes < 0 ? controller.Minutes : item.Minutes; this._Seconds = item.Seconds; this._Name = item.Name; this._Suffix = item.Suffix; #region define whether object is currently used in cache _IsUsed = false; if (item.IsIterating) { _EnumeratedElements = new List <string>(); IDictionaryEnumerator enumerator = _Cache.GetEnumerator(); bool typeIsInitialized = false; while (enumerator.MoveNext()) { if (enumerator.Key.ToString().ToLower().EndsWith(this.Suffix.ToLower())) { _EnumeratedElements.Add(enumerator.Key.ToString()); _IsUsed = true; if (!typeIsInitialized) { this._Type = _Cache[enumerator.Key.ToString()].GetType(); typeIsInitialized = true; } } } } else { object obj = _Cache[this.Name]; if (obj != null) { _IsUsed = true; this._Type = obj.GetType(); } else { _IsUsed = false; } } #endregion }
private static void TestLoadWithCallback(ICacheController cache, CacheDataController data) { var loadNotificationCount = 0; var startStatusReceived = false; var completeStatusRecieved = false; var mre = new ManualResetEvent(false); Action<LoadingStatus, int, string> callback = (status, loadingKey, loadingMessage) => { switch (status) { case LoadingStatus.Starting: startStatusReceived = true; break; case LoadingStatus.Loading: break; case LoadingStatus.Loaded: completeStatusRecieved = true; break; default: throw new ArgumentOutOfRangeException("status"); } // ReSharper disable AccessToModifiedClosure loadNotificationCount++; // ReSharper restore AccessToModifiedClosure }; cache.SetupLoadNotification(typeof(TestCacheData), CacheNotificationAction.Add, callback); var callbackRaised = false; data.LoadWithCallback(() => { callbackRaised = true; mre.Set(); }); mre.WaitOne(1000); Assert.IsTrue(callbackRaised, "Callback was not raised"); Assert.IsTrue(startStatusReceived, "Start status missing"); Assert.IsTrue(loadNotificationCount == 2, "There should be 2 LoadNotification messages"); Assert.IsTrue(completeStatusRecieved, "Complete status missing"); cache.SetupLoadNotification(typeof(TestCacheData), CacheNotificationAction.Remove, callback); // Return to a IsCached = false state cache.Invalidate(); }
public T Request <T>(PrimaryKey?id) where T : Entity { if (id == null) { return(null); } IdentityTuple tuple = new IdentityTuple(typeof(T), id.Value); Entity ident; if (entityCache.TryGetValue(tuple, out ident)) { return((T)ident); } if (retrieved.TryGetValue(tuple, out ident)) { return((T)ident); } ICacheController cc = Schema.Current.CacheController(typeof(T)); if (cc != null && cc.Enabled) { T entityFromCache = EntityCache.Construct <T>(id.Value); cc.Complete(entityFromCache, this); retrieved.Add(tuple, entityFromCache); return(entityFromCache); } ident = (T)requests?.TryGetC(typeof(T))?.TryGetC(id.Value); if (ident != null) { return((T)ident); } T entity = EntityCache.Construct <T>(id.Value); if (requests == null) { requests = new Dictionary <Type, Dictionary <PrimaryKey, Entity> >(); } requests.GetOrCreate(tuple.Type).Add(tuple.Id, entity); return(entity); }
private static void TestLoadWithDataInDataStore(ICacheController cache, MemoryCacheDataStore dataStore) { cache.Save(); var rawDataStore = dataStore.Storage; var dataStore2 = new MemoryCacheDataStore { Storage = rawDataStore }; var cache2 = new CacheController(); cache2.SetupDataStore(dataStore2); cache2.Load(); var data2 = cache2.Cache[0].Data as TestCacheData; Assert.IsNotNull(data2); Assert.IsTrue(data2.Model == MODEL_DATA, "Model text did not match"); }
static Dictionary <PrimaryKey, string> GetStrings <T>(List <PrimaryKey> ids) where T : Entity { ICacheController cc = Schema.Current.CacheController(typeof(T)); if (cc != null && cc.Enabled) { cc.Load(); return(ids.ToDictionary(a => a, a => cc.TryGetToString(a))); } else { return(ids.GroupsOf(Schema.Current.Settings.MaxNumberOfParameters) .SelectMany(gr => Database.Query <T>().Where(e => gr.Contains(e.Id)).Select(a => KVP.Create(a.Id, a.ToString()))) .ToDictionary()); } }
public void ReadWordTest5_FirstRepresentativeZero() { ICacheController <int> cacheController = CreateController(); int linesPerSet_Mod = (int)Math.Pow(2, kLinesDegree) / kNumberOfWays;; // iterate throug all members of class [0] = Z linesPerSet_Mod = Z mod linesPerSet_Mod // rep = representative int rep = kMinSequentialUserID; for (int c = 0, tag = rep + linesPerSet_Mod * c; tag <= kMaxSequentialUserID; ++c, tag = rep + linesPerSet_Mod * c) { Word word = cacheController.ReadWord(tag); Assert.AreEqual(word.SetIndex, c % kNumberOfWays); } }
/// <summary> /// /// </summary> public void Initialize() { // Initialize FlushInterval _flushInterval.Initialize(); try { if (_implementation == null) { throw new DataMapperException ("Error instantiating cache controller for cache named '"+_id+"'. Cause: The class for name '"+_implementation+"' could not be found."); } // Build the CacheController Type type = TypeUtils.ResolveType(_implementation); object[] arguments = new object[0]; _controller = (ICacheController)Activator.CreateInstance(type, arguments); } catch (Exception e) { throw new ConfigurationException("Error instantiating cache controller for cache named '"+_id+". Cause: " + e.Message, e); } //------------ configure Controller--------------------- try { _controller.Configure(_properties); } catch (Exception e) { throw new ConfigurationException ("Error configuring controller named '"+_id+"'. Cause: " + e.Message, e); } }