/// <summary> /// Updates cache after exit from play mode or creation of new pool. /// </summary> private void UpdateCache() { if (currentCacheId != "") { // true if there is no saved cache bool init = !cache.ContainsLevel(currentCacheId); List <PoolCache> newCache = new List <PoolCache>(); for (int i = 0; i < pools.Count; i++) { // if we initializing cache we simple adding current pool info if (init) { newCache.Add(new PoolCache(pools[i].name, pools[i].poolSize)); } // if there is a cache, let's update this stuff else { int index = cache.poolsCache[currentCacheId].FindIndex(x => x.poolName == pools[i].name); if (index != -1) { // do not consider new data if it's (probably pool just was not used at all) if (pools[i].maxItemsUsedInOneTime != 0) { cache.poolsCache[currentCacheId][index].UpdateSize(pools[i].maxItemsUsedInOneTime); } newCache.Add(cache.poolsCache[currentCacheId][index]); } else { newCache.Add(new PoolCache(pools[i].name, pools[i].poolSize)); } } } if (init) { cache.poolsCache.Add(currentCacheId, newCache); } else { cache.UpdateCache(currentCacheId, newCache); } Serializer.SerializeToPDP(cache, CACHE_FILE_NAME); } else { Debug.LogError("[PoolManager] Cache could not be updated. This level was not initialized."); } }
private void DisplayCacheState() { List <PoolCache> currentLevelCache = LoadCurrentCache(); if (!currentLevelCache.IsNullOrEmpty()) { List <PoolCache> cacheToDelete = new List <PoolCache>(); string cacheInfo = string.Empty; foreach (PoolCache poolCache in currentLevelCache) { // if pool not exists - delete it's cache int index = poolManagerRef.pools.FindIndex(x => x.name == poolCache.poolName); if (index == -1) { cacheToDelete.Add(poolCache); } // otherwise adding pool and cache stats to log else { cacheInfo += poolCache.poolName + "\tcurrent size: " + poolManagerRef.pools[index].poolSize + "\tcached size: " + poolCache.poolSize + "\t(updates count: " + poolCache.updatesCount + ")\n"; } } // deleting all obsolete cache if (cacheToDelete.Count > 0) { if (cacheInfo != string.Empty) { cacheInfo += "\n"; } foreach (PoolCache currentCache in cacheToDelete) { currentLevelCache.Remove(currentCache); cacheInfo += "deleted cache for unexisting pool: \"" + currentCache.poolName + "\"\n"; } PoolManagerCache allCache = LoadAllCache(); allCache.UpdateCache(GetCurrentCacheId(), currentLevelCache); Serializer.SerializeToPDP(allCache, PoolManager.CACHE_FILE_NAME); } Debug.Log(cacheInfo); } else { Debug.Log("[PoolManager] There's no saved cache for current scene."); } }
private void UpdateIgnoreCacheStateOfPool(string poolName, bool newState) { List <PoolCache> poolCacheList = LoadCurrentCache(); int index = poolCacheList.FindIndex(x => x.poolName == poolName); if (index != -1) { poolCacheList[index].ignoreCache = newState; } PoolManagerCache allCache = LoadAllCache(); allCache.UpdateCache(GetCurrentCacheId(), poolCacheList); Serializer.SerializeToPDP(allCache, PoolManager.CACHE_FILE_NAME); }
private void RenameCachedPool(string oldName, string newName) { List <PoolCache> poolCacheList = LoadCurrentCache(); int index = poolCacheList.FindIndex(x => x.poolName == oldName); if (index != -1) { poolCacheList[index].poolName = newName; } PoolManagerCache allCache = LoadAllCache(); allCache.UpdateCache(GetCurrentCacheId(), poolCacheList); Serializer.SerializeToPDP(allCache, PoolManager.CACHE_FILE_NAME); }
private void ClearObsoleteCache() { List <PoolCache> currentLevelCache = LoadCurrentCache(); if (currentLevelCache != null) { List <PoolCache> cacheToDelete = new List <PoolCache>(); foreach (PoolCache poolCache in currentLevelCache) { // if pool not exists - delete it's cache int index = poolManagerRef.pools.FindIndex(x => x.name == poolCache.poolName); if (index == -1) { cacheToDelete.Add(poolCache); } } // deleting all obsolete cache if (cacheToDelete.Count > 0) { string updateLog = ""; foreach (PoolCache currentCache in cacheToDelete) { currentLevelCache.Remove(currentCache); updateLog += "deleted cache for unexisting pool: \"" + currentCache.poolName + "\"\n"; } Debug.Log(updateLog); PoolManagerCache allCache = LoadAllCache(); allCache.UpdateCache(GetCurrentCacheId(), currentLevelCache); Serializer.SerializeToPDP(allCache, PoolManager.CACHE_FILE_NAME); } } }