public SmsKeyStorageCache(ICacheNotify <SmsKeyCacheKey> keyCacheNotify) { CheckCache = AscCache.Memory; KeyCache = AscCache.Memory; KeyCacheNotify = keyCacheNotify; KeyCacheNotify.Subscribe(r => KeyCache.Remove(r.Key), CacheNotifyAction.Remove); }
/// <summary> /// Resolves the deduplicated entity. /// </summary> /// <param name="entity">The entity to deduplicate.</param> /// <param name="primaryKey">The primary key of the entity.</param> /// <returns>The deduplicated entity.</returns> protected virtual TEntityType Deduplicate(TEntityType entity, object primaryKey) { if (KeyCache.ContainsKey(primaryKey)) { return(KeyCache[primaryKey]); } return(entity); }
internal static void CacheVanillaState() { KeyCaches = new[] { KeyCache.Create(Filters.Scene._effects), KeyCache.Create(SkyManager.Instance._effects), KeyCache.Create(Overlays.Scene._effects), KeyCache.Create(Overlays.FilterFallback._effects), KeyCache.Create(GameShaders.Misc) }; vanillaArmorShaderCount = GameShaders.Armor._shaderDataCount; vanillaHairShaderCount = GameShaders.Hair._shaderDataCount; }
public bool ExistsKey(string phone) { if (string.IsNullOrEmpty(phone)) { return(false); } lock (KeyLocker) { var cacheKey = BuildCacheKey(phone); var phoneKeys = KeyCache.Get <Dictionary <string, DateTime> >(cacheKey); return(phoneKeys != null); } }
private void Start() { allKeyCodes = new KeyCode[(int)KeyCodeIndex.KeyCodeLength]; allKeyCodes[(int)KeyCodeIndex.UpKeyCodeIdx] = inputInfo.upKey; allKeyCodes[(int)KeyCodeIndex.DownKeyCodeIdx] = inputInfo.downKey; allKeyCodes[(int)KeyCodeIndex.LeftKeyCodeIdx] = inputInfo.leftKey; allKeyCodes[(int)KeyCodeIndex.RightKeyCodeIdx] = inputInfo.rightKey; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx1] = inputInfo.baseSkillKey1; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx2] = inputInfo.baseSkillKey2; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx3] = inputInfo.baseSkillKey3; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx4] = inputInfo.baseSkillKey4; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx5] = inputInfo.baseSkillKey5; allKeyCodes[(int)KeyCodeIndex.BaseSkillKeyCodeIdx6] = inputInfo.baseSkillKey6; KeyCode[] upKeyArray = GetKeyCodes(KeyCodeIndex.UpKeyCodeIdx); KeyCode[] downKeyArray = GetKeyCodes(KeyCodeIndex.DownKeyCodeIdx); KeyCode[] leftKeyArray = GetKeyCodes(KeyCodeIndex.LeftKeyCodeIdx); KeyCode[] rightKeyArray = GetKeyCodes(KeyCodeIndex.RightKeyCodeIdx); KeyCode[] baseSkillKey1KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx1); KeyCode[] baseSkillKey2KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx2); KeyCode[] baseSkillKey3KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx3); KeyCode[] baseSkillKey4KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx4); KeyCode[] baseSkillKey5KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx5); KeyCode[] baseSkillKey6KeyArray = GetKeyCodes(KeyCodeIndex.BaseSkillKeyCodeIdx6); upDoubleKeyDownCache = new KeyCache(upKeyArray, Time.deltaTime * 10, false); downDoubleKeyDownCache = new KeyCache(downKeyArray, Time.deltaTime * 10, false); leftDoubleKeyDownCache = new KeyCache(leftKeyArray, Time.deltaTime * 10, false); rightDouableKeyDownCache = new KeyCache(rightKeyArray, Time.deltaTime * 10, false); baseSkillKey1DouableKeyDownCache = new KeyCache(baseSkillKey1KeyArray, Time.deltaTime * 10, false); baseSkillKey2DouableKeyDownCache = new KeyCache(baseSkillKey2KeyArray, Time.deltaTime * 10, false); baseSkillKey3DouableKeyDownCache = new KeyCache(baseSkillKey3KeyArray, Time.deltaTime * 10, false); baseSkillKey4DouableKeyDownCache = new KeyCache(baseSkillKey4KeyArray, Time.deltaTime * 10, false); baseSkillKey5DouableKeyDownCache = new KeyCache(baseSkillKey5KeyArray, Time.deltaTime * 10, false); baseSkillKey6DouableKeyDownCache = new KeyCache(baseSkillKey6KeyArray, Time.deltaTime * 10, false); keysCache = new KeyCache(allKeyCodes, Time.deltaTime * 3, false, allKeyCodes.Length); codeCachePairs.Add(inputInfo.upKey, upDoubleKeyDownCache); codeCachePairs.Add(inputInfo.downKey, downDoubleKeyDownCache); codeCachePairs.Add(inputInfo.leftKey, leftDoubleKeyDownCache); codeCachePairs.Add(inputInfo.rightKey, rightDouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey1, baseSkillKey1DouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey2, baseSkillKey2DouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey3, baseSkillKey3DouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey4, baseSkillKey4DouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey5, baseSkillKey5DouableKeyDownCache); codeCachePairs.Add(inputInfo.baseSkillKey6, baseSkillKey6DouableKeyDownCache); }
/// <summary> /// Maps a row of data to an entity. /// </summary> /// <param name="context">A context that contains information used to map Dapper objects.</param> /// <returns>The mapped entity, or null if the entity has previously been returned.</returns> public virtual TEntityType Map(EntityMapContext context) { if (PrimaryKey == null) { throw new InvalidOperationException("PrimaryKey selector is not defined, but is required to use DeduplicatingEntityMapper."); } // Deduplicate the top object (entity) in the list if (context.Items != null && context.Items.Any()) { if (context.Items.First() is TEntityType entity) { var previous = entity; var primaryKey = PrimaryKey(entity); if (primaryKey == null) { throw new InvalidOperationException("A null primary key was provided, which results in an unpredictable state."); } // Deduplicate the entity using available information entity = Deduplicate(entity, primaryKey); if (!object.ReferenceEquals(previous, entity)) { context.Items = new[] { entity }.Concat(context.Items.Skip(1)); } // Map the object var next = Mapper.Map(context); // Return null if we are returning a duplicate object. // Queries can filter out null entries to prevent duplicates. if (ReturnsNullWithDuplicates && KeyCache.ContainsKey(primaryKey)) { return(null); } // Cache a reference to the entity KeyCache[primaryKey] = next; // And, return it return(next); } } return(default(TEntityType)); }
protected override void InitializePrimaryKeyCache() { var entries = DbSet.Include(x => x.Timeline).ToList(); var allPrimaryKeys = entries.Select(x => x.PrimaryKey).Distinct(); var activePrimaryKeys = entries.Where(x => x.MostRecentEntry?.EndDate == null).Select(x => x.PrimaryKey).Distinct(); var cache = new HashSet <TPrimaryKey>(allPrimaryKeys); Logger?.LogTrace($"Initializing primary key link hash cache. [{cache.Count}] entries found in database."); KeyCache.InitializeKeyCache <TLink, TPrimaryKey>(typeof(TLink), cache); cache = new HashSet <TPrimaryKey>(activePrimaryKeys); Logger?.LogTrace($"Initializing primary key active link hash cache. [{cache.Count}] entries found in database."); KeyCache.InitializeKeyCache <TSatelliteTimeline, TPrimaryKey>(typeof(TSatelliteTimeline), cache); }
public Result ValidateKey(string phone, string key) { key = (key ?? string.Empty).Trim(); if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(key)) { return(Result.Empty); } var cacheCheck = BuildCacheKey("check" + phone); int.TryParse(CheckCache.Get <string>(cacheCheck), out var counter); if (++counter > AttemptCount) { return(Result.TooMuch); } CheckCache.Insert(cacheCheck, counter.ToString(CultureInfo.InvariantCulture), DateTime.UtcNow.Add(StoreInterval)); lock (KeyLocker) { var cacheKey = BuildCacheKey(phone); var phoneKeys = KeyCache.Get <Dictionary <string, DateTime> >(cacheKey); if (phoneKeys == null) { return(Result.Timeout); } if (!phoneKeys.ContainsKey(key)) { return(Result.Invalide); } var createDate = phoneKeys[key]; SmsKeyStorageCache.RemoveFromCache(cacheKey); if (createDate.Add(StoreInterval) < DateTime.UtcNow) { return(Result.Timeout); } CheckCache.Insert(cacheCheck, (--counter).ToString(CultureInfo.InvariantCulture), DateTime.UtcNow.Add(StoreInterval)); return(Result.Ok); } }
/// <summary> /// prüft ob doc existiert /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <bool> ExistsDocument <T>(string id) where T : Entity { var source = CreateQuery <T>(new FeedOptions { MaxItemCount = 1, EnableCrossPartitionQuery = false }) .Where(x => x.EntityId == id && x.EntityType == KeyCache.GetEntityTypeKey <T>()); var query = source.AsDocumentQuery(); if (query.HasMoreResults) { var result = await query.ExecuteNextAsync().ConfigureAwait(false); _logger.LogTrace("ExistsDocument: {DocumentId} RequestUnits: {RequestCharge} ", id, result.RequestCharge); if (result.Any()) { return(true); } } return(false); }
public bool GenerateKey(string phone, out string key) { if (string.IsNullOrEmpty(phone)) { throw new ArgumentNullException("phone"); } lock (KeyLocker) { var cacheKey = BuildCacheKey(phone); var phoneKeys = KeyCache.Get <Dictionary <string, DateTime> >(cacheKey) ?? new Dictionary <string, DateTime>(); if (phoneKeys.Count > AttemptCount) { key = null; return(false); } key = new Random().Next((int)Math.Pow(10, KeyLength - 1), (int)Math.Pow(10, KeyLength)).ToString(CultureInfo.InvariantCulture); phoneKeys[key] = DateTime.UtcNow; KeyCache.Insert(cacheKey, phoneKeys, DateTime.UtcNow.Add(StoreInterval)); return(true); } }
public IMongoCollection <T> GetCol <T>() where T : Entity { return(Database.Value.GetCollection <T>(KeyCache.GetEntityTypeKey <T>())); }
protected bool RemoveIfKeyIsUnique <T>(TPrimaryKey primaryKey) { var PrimaryKeys = KeyCache.GetCachedKeys <T, TPrimaryKey>(typeof(T)); return(PrimaryKeys.Remove(primaryKey)); }