1 Star 0 Fork 33

fnet/NScript

forked from 车江毅/NScript 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CompilerCache.cs 917 Bytes
一键复制 编辑 原始数据 按行查看 历史
车江毅 提交于 2016-06-24 10:21 +08:00 . add project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BSF.BaseService.NScript.Core
{
public class CompilerCache
{
private Dictionary<int, CompilerResult> _cache = new Dictionary<int, CompilerResult>();
private object _cacheLock = new object();
public CompilerResult GetOrAdd(int hash,Func<CompilerResult> func)
{
if (_cache.ContainsKey(hash))
{
return _cache[hash];
}
else
{
lock (_cacheLock)
{
var result = func.Invoke();
_cache.Add(hash, result);
return _cache[hash];
}
}
}
public void Clear()
{
lock (_cacheLock)
{
_cache.Clear();
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fnet/NScript.git
git@gitee.com:fnet/NScript.git
fnet
NScript
NScript
master

搜索帮助