This action will force synchronization from 车江毅/NScript, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace BSF.BaseService.NScript.Core{/// <summary>/// 字符串解析器/// 缓存解析结果,加快下次解析/// </summary>public class StringParser<T>{private Dictionary<string, T> cache = new Dictionary<string, T>();private readonly int recoverCount = 5000;//随机回收限制,未来替换为高性能的LRUpublic void ClearCache(){lock (this){cache.Clear();}}public T Parser(string key, Func<T> func){if (cache.ContainsKey(key)){return cache[key];}else{lock (this){if (!cache.ContainsKey(key)){//随机回收一半if (cache.Count > recoverCount){List<string> recoverKeys = new List<string>(cache.Keys);for (int i = 0; i < recoverCount / 2; i++){int keyIndex = new Random(new Guid().GetHashCode()).Next(recoverKeys.Count);cache.Remove(recoverKeys[keyIndex]);recoverKeys.RemoveAt(keyIndex);}}T t = func.Invoke();cache.Add(key, t);}return cache[key];}}}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。