缓存(关联文件)处理
来源:互联网 发布:决策树分类实现Python 编辑:程序博客网 时间:2024/05/06 20:51
参考:http://msdn.microsoft.com/library/system.runtime.caching.memorycache(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
引用:System.Runtime.Caching.dll,如下测试,fm4.5
static void CacheTest() { string cname = "filescontents"; ObjectCache cc = MemoryCache.Default; string fileContents = cc[cname] as string; if (fileContents == null) { CacheItemPolicy policy = new CacheItemPolicy(); TimeSpan sp = new TimeSpan(0, 1, 0); policy.SlidingExpiration = sp; List<string> filePaths = new List<string>(); string path = System.IO.Directory.GetCurrentDirectory() + "\\example.txt"; filePaths.Add(path); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); fileContents = System.IO.File.ReadAllText(path, Encoding.Default); cc.Set(cname, fileContents, policy); } Console.WriteLine(fileContents); }
static void Main(string[] args) { //ExecuteCode(WriteData); //ExecuteCode(ReadData); //ExecuteCode(TransData); bool quit = false; while (!quit) { Console.Write("get cache: "); string demo = Console.ReadLine(); switch (demo) { case "Y": ExecuteCode(CacheTest); break; case "Q": quit = true; break; default: Console.WriteLine("Choose a Word of Y and Q(to quit)"); break; } } Console.ReadKey(); } public static void ExecuteCode(Action a) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); a(); stopwatch.Stop(); TimeSpan timespan = stopwatch.Elapsed; Console.WriteLine("运行{0}秒", timespan.TotalSeconds); }
0 0
- 缓存(关联文件)处理
- js 文件缓存处理方法
- 静态文件的缓存处理
- Swift之缓存文件处理
- hadoop 处理不同的输入文件,文件关联
- hadoop 处理不同的输入文件,文件关联
- java缓存处理(二)
- Python文件处理之文件写入方式与写缓存
- 文件关联
- 文件关联
- 文件关联
- 文件关联
- 文件关联
- 文件关联
- 文件关联
- 缓存处理
- Hibernate的缓存的原理(关联的数据查询出来如何缓存的)
- 目录文件处理函数之clearstatcache函数--清除缓存
- C#对FTP的操作(上传,下载,重命名文件,删除文件,文件存在检查)
- Python提示Tkinter模块找不到解决
- 2014.10.11
- win7+vs2010+opencv,opencv的安装和配置
- 阅读优秀代码是提高开发人员修为的一种捷径
- 缓存(关联文件)处理
- jQuery框架代码解析
- cocos2d-x lua 场景的创建
- IOS6之AutoLayout(一)
- I2C协议及使用简析
- 欧拉函数 算法摘记 数论
- browser下载文件名乱码
- IE网页截图技术笔记
- boost库shared_ptr实现桥接模式