share memory cache across multi web application
Single instance of a MemoryCache across multiple application pools on the same server [duplicate]
You could create a separate Web Api project and host your implementation of the MemoryCache there. Then expose an api that gets / sets items from the cache that all of your apps can use.
Though, there are caveats with this approach. For example, if you use MemoryCache.Default then your cache lives as long as your application pool lives - the default application pool idle time-out is 20 minutes which is less than 1 hour. What I'm getting to is that I think you will have to keep a lot of the App Pool settings in sync and I believe this will lead to issues.
A better approach is to implement a distributed cache. I recommend using Redis and the StackExchange.Redis client. There are other alternatives such as memcached.
Suggestions for simple .NET distributed caching solution
解答1
memcached along with an ASP.NET provider is a popular choice. Bear in mind though that in .NET 4.0 the recommended way to do caching is to use the new ObjectCache instead of HttpRuntime.Cache
. There is a built in memory implementation into the .NET framework (MemoryCache) and also you may checkout an implementation for memcached.
解答2
Simple, fast, lightweight and safe sound like things like redis and memcached, which can be very effective as a central cache. For stackoverflow we use redis via BookSleeve (client) but most stores will work similarly. There is also an AppFabric cache, but that is considerably more complex.
Key points though:
- your data will need to be serializable in some way
- if you are currently using cache of large objects (like a big DataTable) you'll need to consider bandwidth implications, or make it more granular
- you'd probably benefit from a 2-tier cache (one local memory, with the central store as secondary)
- which means you'd also need to consider invalidation (we do that via the pub/sub API in redis)
Sharing cache between apps (asp.net) on the same physical machine
Can not be done. Multiple asp.net apps live in their own appdomain, and the appdomain is IIS controlled and may cycle at any time. This means any caching HAS to use networking scenarios (remoting etc.) and the cache better be suited outside the ASP.NET control (system service).
ASP.Net Cache sharing
While others have mentioned the built in ASP.NET Cache (System.Web.Caching), please note that .NET 4.0 introduces a whole new caching framework designed to work outside of the System.Web.Caching namespace:
System.Runtime.Caching
http://msdn.microsoft.com/en-us/library/system.runtime.caching(VS.100).aspx
Now, this is much more of a beast than the simple System.Web.Caching's Cache item. But, you get the advantage of having multiple cache stores, locking of cache objects/keys, and the extensibility points of creating your own external cache providers - such as one for Microsoft's new Velocity distributed caching system. It comes with a MemoryCache provider built-in.
It's really not that difficult to use. Straight from MSDN's article on the built-in MemoryCache provider (again, you can implement your own) using it in a WinForms application (you'd change the code for your web app):
http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx
ObjectCache cache = MemoryCache.Default;
string fileContents = cache["filecontents"] as string;
if (fileContents == null)
{
CacheItemPolicy policy = new CacheItemPolicy();
List<string> filePaths = new List<string>();
filePaths.Add("c:\\cache\\example.txt");
policy.ChangeMonitors.Add(new
HostFileChangeMonitor(filePaths));
// Fetch the file contents.
fileContents =
File.ReadAllText("c:\\cache\\example.txt");
cache.Set("filecontents", fileContents, policy);
}
Label1.Text = fileContents;
I've implemented NCache (mentioned above), as well as Memcached. I can tell you that Microsoft's Velocity is really the way to go for partitioning the data and setting up redundancy within the cache partitions itself (very cool). Not to mention, it's free!
share memory cache across multi web application的更多相关文章
- ThreadLocal Memory Leak in Java web application - Tomcat
ThreadLocal variables are infamous for creating memory leaks. A memory leak in Java is amount of mem ...
- The web application registered the JDBC driver * but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
最近使用了最新版的tomcat9,使用jdbc链接mysql数据库.关闭tomcat过程中出现警告 13-Sep-2017 22:22:54.369 WARNING [main] org.apache ...
- Why does the memory usage increase when I redeploy a web application?
That is because your web application has a memory leak. A common issue are "PermGen" memor ...
- The web application [ ] registered the JDBC driver [net.sourceforge.jtds.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver
出现以下错误时,我找了很多方法,都未解决,网上有很多,最后我实在无奈,怀疑会不会是Tomcat的原因,更换了一个版本之后就好了.The web application [ ] registered t ...
- 严重: The web application [] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDB
idea项目启动报如下错误, 网上的方法都试了都没用, 一直没解决, 干掉项目, 重新从svn检出就好了...坑 啊 Root WebApplicationContext: initializatio ...
- registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
问题是tomcat的版本问题,tomcat新检测机制导致的这个问题,换版本可以解决问题,但不建议这么做,租用服务器不是你说换就换的.其实问题根源是BasicDataSource,BasicDataSo ...
- 错误:created a ThreadLocal with key of type ……but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
tomcat reload显示错误:SEVERE: The web application [/Interceptor] created a ThreadLocal with key of type ...
- 解决:The web application [] registered the JDBC driver [] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
问题描述 在将Spring Boot程序打包生成的war包部署到Tomcat后,启动Tomcat时总是报错,但是直接在IDEA中启动Application或者用"java -jar" ...
- Creating an API-Centric Web Application[转]
Creating an API-Centric Web Application 转自 http://hub.tutsplus.com/tutorials/creating-an-api-centric ...
随机推荐
- 后端技术杂谈4:Elasticsearch与solr入门实践
阮一峰:全文搜索引擎 Elasticsearch 入门教程 作者:阮一峰 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://g ...
- linux记事工具:RedNotebook Lifeograph Kontact ThotKeeper
Linux桌面有许多灵活而功能强大的日记工具,如支持标签.加密.多种日志模版和实时搜索.其中的优秀者包括: RedNotebook Lifeograph Kontact ThotKeeper
- 14. Jmeter-配置元件一
jmeter-配置元件介绍与使用 CSV 数据文件设置 HTTP信息头管理器 HTTP Cookie 管理器 HTTP Cache Manager HTTP请求默认值 计数器 DNS Cache Ma ...
- java多线程学习笔记(八)
本节开始线程间通信: 使用wait/notify实现线程间通信 生产者/消费者模式的实现 方法join的使用 ThreadLocal类的使用 可以通过使用 sleep() 结合 while(true) ...
- spring, spring mvc, mybatis整合文件配置详解
转自:http://www.cnblogs.com/wxisme/p/4924561.html 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用 ...
- leetcode.分治.241为运算表达式设计优先级-Java
1. 具体题目 给定一个含有数字和运算符的字符串,为表达式添加括号,改变其运算优先级以求出不同的结果.你需要给出所有可能的组合的结果.有效的运算符号包含 +, - 以及 * . 示例 1: 输入: & ...
- java面试题-看到那记录到哪
哈希冲突 如果两个不同的元素,通过哈希函数得到的实际存储地址相同怎么办?也就是说,当我们对某个元素进行哈希运算,得到一个存储地址,然后要进行插入的时候,发现已经被其他元素占用了,其实这就是所谓的哈希冲 ...
- linux基本命令的简单介绍
基本命令 man:查看帮助信息 :一般系统命令太多,要记住这些命令是不可能的,man是一个联机帮助信息 man提供大量的帮助信息,一般分为以下4各部分 NAME:对命令的简单介绍 SYNOPSIS对命 ...
- nginx 反向代理服务
目录 Nginx代理服务基本概述 Nginx代理服务常见模式 Nginx代理服务支持协议 Nginx反向代理配置语法 Nginx反向代理场景实践 配置代理实战 在lb01上安装nginx Nginx代 ...
- win10定时任务
1.设置everything开机启动 电脑--管理