- 浏览: 196999 次
- 来自: ...
文章分类
- 全部博客 (180)
- OSGi (1)
- Spring (8)
- WebTech (15)
- Architecture (5)
- JavaConcept (1)
- JGroups (2)
- 传统cache (3)
- Andriod (1)
- 日志 (4)
- web安全 (1)
- hbase (1)
- json (3)
- java&jvm (8)
- spark (1)
- Javascript (3)
- 互联网 (4)
- 云计算 (1)
- 大数据 (1)
- 开发构建工具 (20)
- 分布式系统 (6)
- MessageQueue (2)
- design (4)
- 思维 (2)
- 微服务 (11)
- 算法 (1)
- NOSQL (1)
- 编程 (4)
- redis (7)
- 网管 (4)
- snmp (3)
- JPA (5)
- JUnit (2)
- 搜索 (4)
- tika (1)
- mysql (13)
- docker (3)
- 远程工具 (1)
- 运维 (10)
- 认证 (4)
- netty (2)
- 二维码 (1)
- mybatis3 (1)
- Markdown (1)
- shiro (1)
- kafka (1)
- ELK (1)
- 正则表达式 (1)
- kubernetes (3)
最新评论
-
Norther:
注入都比较麻烦 现在的折衷办法就是回归原始 在DomainOb ...
使用Spring的情况下如何将Dao注入DomainObject? -
pig345:
最近也在看这个问题,spring确实 和 DomainObje ...
使用Spring的情况下如何将Dao注入DomainObject? -
piper:
版主,需要这么复杂的配置吗?我记得以前和ehcache结合的时 ...
using springmodules-cache -
littcai:
支持一下,正准备实践一下
using springmodules-cache -
huangxx:
没有实践过
支持分享
using springmodules-cache
项目进入了后期阶段,发现了不少的性能问题,其中有部分领域对象在应用的某些阶段相对稳定,于是准备采用cache,减少对象构建次数,减少数据库访问次数,有针对性地改善性能问题。
using springmodules-cache的主要原因是其屏蔽了各个不同cache产品的接口差异性,提供了一致的编程模型,已经实现adapter的包括: EHCache, JBoss Cache, Java Caching System (JCS) and OSCache。
由于我们的项目已经使用了spring2.0,要引入oscache,需要做的工作如下:
-
需要的jar包括:jgroups-all.jar,oscache-2.3.2.jar,spring-modules-cache.jar,spring.jar,commons-logging.jar,jakarta-oro.jar.
-
增加了ArgumentsCacheKeyGenerator类,实现org.springmodules.cache.key.CacheKeyGenerator接口。不使用sm自带的hashcodecachekeygenerator原因是,想自己能够在其它模块手动生成cacheKey,以便主动refresh cache。java 代码
- import java.io.Serializable;
- import org.aopalliance.intercept.MethodInvocation;
- import org.springmodules.cache.key.CacheKeyGenerator;
- public class ArgumentsCacheKeyGenerator implements CacheKeyGenerator {
- private String prefix="";
- public Serializable generateKey(MethodInvocation mi) {
- // TODO Auto-generated method stub
- StringBuffer sb = new StringBuffer();
- sb.append(this.getPrefix()).append('_');
- Object[] args = mi.getArguments();
- for( int i=0; i
- sb.append(args[i]);
- }
- return sb.toString();
- }
- public String getPrefix() {
- return prefix;
- }
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
- }
-
增加了oscache_config.properties,cache容量为100个对象,调度算法为LRU。java 代码
- # CACHE ALGORITHM
- #
- # Default cache algorithm to use. Note that in order to use an algorithm
- # the cache size must also be specified. If the cache size is not specified,
- # the cache algorithm will be Unlimited cache.
- #
- cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
- # cache.algorithm=com.opensymphony.oscache.base.algorithm.FIFOCache
- # cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache
- # CACHE SIZE
- #
- # Default cache size in number of items. If a size is specified but not
- # an algorithm, the cache algorithm used will be LRUCache.
- #
- cache.capacity=100
- # CACHE IN MEMORY
- #
- # If you want to disable memory caching, just uncomment this line.
- #
- # cache.memory=false
- # CACHE KEY
- #
- # This is the key that will be used to store the cache in the application
- # and session scope.
- #
- # If you want to set the cache key to anything other than the default
- # uncomment this line and change the cache.key
- #
- # cache.key=__oscache_cache
- # USE HOST DOMAIN NAME IN KEY
- #
- # Servers for multiple host domains may wish to add host name info to
- # the generation of the key. If this is true, then uncomment the
- # following line.
- #
- # cache.use.host.domain.in.key=true
- # CACHE LISTENERS
- #
- # These hook OSCache events and perform various actions such as logging
- # cache hits and misses, or broadcasting to other cache instances across a cluster.
- # See the documentation for further information.
- #
- # cache.event.listeners=com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener, \
- # com.opensymphony.oscache.extra.CacheEntryEventListenerImpl, \
- # com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl, \
- # com.opensymphony.oscache.extra.ScopeEventListenerImpl
- # CACHE PERSISTENCE CLASS
- #
- # Specify the class to use for persistence. If you use the supplied DiskPersistenceListener,
- # don't forget to supply the cache.path property to specify the location of the cache
- # directory.
- #
- # If a persistence class is not specified, OSCache will use memory caching only.
- #
- # cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
- # CACHE OVERFLOW PERSISTENCE
- # Use persistent cache in overflow or not. The default value is false, which means
- # the persistent cache will be used at all times for every entry. true is the recommended setting.
- #
- # cache.persistence.overflow.only=true
- # CACHE DIRECTORY
- #
- # This is the directory on disk where caches will be stored by the DiskPersistenceListener.
- # it will be created if it doesn't already exist. Remember that OSCache must have
- # write permission to this directory.
- #
- # Note: for Windows machines, this needs \ to be escaped
- # ie Windows:
- # cache.path=c:\\myapp\\cache
- # or *ix:
- # cache.path=/opt/myapp/cache
- #
- # cache.path=c:\\app\\cache
- # THREAD BLOCKING BEHAVIOR
- #
- # When a request is made for a stale cache entry, it is possible that another thread is already
- # in the process of rebuilding that entry. This setting specifies how OSCache handles the
- # subsequent 'non-building' threads. The default behaviour (cache.blocking=false) is to serve
- # the old content to subsequent threads until the cache entry has been updated. This provides
- # the best performance (at the cost of serving slightly stale data). When blocking is enabled,
- # threads will instead block until the new cache entry is ready to be served. Once the new entry
- # is put in the cache the blocked threads will be restarted and given the new entry.
- # Note that even if blocking is disabled, when there is no stale data available to be served
- # threads will block until the data is added to the cache by the thread that is responsible
- # for building the data.
- #
- # cache.blocking=false
- # CACHE UNLIMITED DISK
- # Use unlimited disk cache or not. The default value is false, which means
- # the disk cache will be limited in size to the value specified by cache.capacity.
- #
- # cache.unlimited.disk=false
- # JMS CLUSTER PROPERTIES
- #
- # Configuration properties for JMS clustering. See the clustering documentation
- # for more information on these settings.
- #
- #cache.cluster.jms.topic.factory=java:comp/env/jms/TopicConnectionFactory
- #cache.cluster.jms.topic.name=java:comp/env/jms/OSCacheTopic
- #cache.cluster.jms.node.name=node1
- # JAVAGROUPS CLUSTER PROPERTIES
- #
- # Configuration properites for the JavaGroups clustering. Only one of these
- # should be specified. Default values (as shown below) will be used if niether
- # property is set. See the clustering documentation and the JavaGroups project
- # (www.javagroups.com) for more information on these settings.
- #
- #cache.cluster.properties=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;\
- #mcast_send_buf_size=150000;mcast_recv_buf_size=80000):\
- #PING(timeout=2000;num_initial_members=3):\
- #MERGE2(min_interval=5000;max_interval=10000):\
- #FD_SOCK:VERIFY_SUSPECT(timeout=1500):\
- #pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800;max_xmit_size=8192):\
- #UNICAST(timeout=300,600,1200,2400):\
- #pbcast.STABLE(desired_avg_gossip=20000):\
- #FRAG(frag_size=8096;down_thread=false;up_thread=false):\
- #pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)
- #cache.cluster.multicast.ip=231.12.21.132
-
增加了cacheContext.xml,spirng中cache的配置文件.xml 代码
- <!---->
- <bean id="cacheManager"></bean><bean id="cacheManager"
- class="org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
<property name="configLocation" value="WEB-INF/oscache_config.properties" />
</bean> <property value="WEB-INF/oscache_config.properties" name="configLocation"></property>
<bean id="cacheProviderFacade" - class="org.springmodules.cache.provider.oscache.OsCacheFacade">
- <property name="cacheManager" ref="cacheManager" />
- bean>
- <bean id="chinatechKeyGenerator" class="cache.key.ArgumentsCacheKeyGenerator" >
- <property name="prefix">
- <value>CHINATECHvalue>
- property>
- bean>
-
修改applicationContext.xmlxml 代码
- <bean id="tc2"
- class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
- <property name="cacheProviderFacade" ref="cacheProviderFacade" />
- <property name="cacheKeyGenerator" ref="chinatechKeyGenerator" />
- <property name="cachingModels">
- <props>
- <prop key="get*">refreshPeriod=600;groups=CHINATECHprop>
- props>
- property>
- <property name="flushingModels">
- <props>
- <prop key="update*">groups=CHINATECHprop>
- props>
- property>
- <property name="target" ref="tc2Target" />
- bean>
-
修改web.xml,增加cacheContext.xml初始化spring配置。
springmodules站点:springmodules.dev.java.net/
oscache站点:www.opensymphony.com/oscache
- mytest.rar (7.8 KB)
- 描述: 上面都是说实际的项目,附件是一个java application的例子,供学习。TestCache测试源程序。需要自己下载需要的jar包。
- 下载次数: 308
评论
3 楼
piper
2007-04-27
版主,需要这么复杂的配置吗?我记得以前和ehcache结合的时候直接写一个xml配到tomcat下面就行了。还有不太明白你的那个附件。
2 楼
littcai
2007-04-27
支持一下,正准备实践一下
1 楼
huangxx
2007-04-26
没有实践过
支持分享
支持分享
发表评论
-
Spring AOP实现逻辑源码分析总结
2016-07-25 11:18 3759AspectJAutoProxyRegistrar 根据@E ... -
Spring JPA实现逻辑源码分析总结
2016-07-25 11:08 59951、TransactionSynchronizationMa ... -
[转]spring容器外注入
2016-03-28 11:56 1226转自:http://www.iteye.com/topic/ ... -
spring-session-redis配置实例
2016-02-24 11:34 1033web.xml配置: <?xml version= ... -
[转]spring发布和接收定制的事件(spring事件传播)
2016-02-18 16:23 619转自:http://blog.csdn.net/it_man ... -
Customizing HttpMessageConverters with Spring Boot and Spring MVC
2016-01-11 15:41 1153Customizing HttpMessageConvert ... -
spring-modules-cache的问题
2010-03-25 17:27 1867当前的spring-modules-cache 0.8版本对于 ...
相关推荐
Screen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-Tensorflow-API-master.zipScreen-Vehicle-Detection-using-...
Working in the Cloud Using Web-Based Applications and Tools to Collaborate Online 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
cordova-file-cache, Cordova应用的出色文件缓存 cordova-file-cacheCordova应用超出色的文件缓存基于 cordova-promise-fs 。正在启动 # fetch code using bower bower install cordova-
Using rack-cache (1.2) Using rack-test (0.6.2) Using hike (1.2.1) Using tilt (1.3.5) Using sprockets (2.1.3) Using actionpack (3.2.1) Using mime-types (1.21) Using polyglot (0.3.3) Using treetop ...
Using-GNU-Assembler,介绍at&t汇编的语法
The Elements of Artificial Intelligence Using Lisp - Steven L. Tanimoto.pdf The Elements of Artificial Intelligence Using Lisp - Steven L. Tanimoto.pdf
Playing Mountain Car Using Actor-Critic MethodPlaying Mountain Car Using Actor-Critic Method
最新出版的Digital Image Processing-An Algorithmic Introduction Using Java-2nd,书很精致,对图像处理的细节解释的非常浅显易懂,不可多得的一本好书,强烈推荐阅读!
Data modeling and database design have undergone significant evolution ...systems, using the ER (entity relationship) approach for conceptual modeling (solely a logical implementation).
4、ContextCapture - Using tie-point constraints.mp4
[算法]Data Structures, Algorithms and Program Style Using C - James F. Korsh.chm
Using Three-Dimensional Design Visualization.pdf
Digital Communication Using Self-Synchronizing Chaotic Pulse Position Modulation.PDF 文献,很宝贵,花了钱买的
using System.Data.Odbc; // 创建ODBC连接字符串 string connectionString = "Driver={InterSystems Cache ODBC};SERVER=;PORT=;DATABASE=;USER=;PASSWORD=<Password>"; // 创建ODBC连接 OdbcConnection conn = ...
Digital Image Processing Using Matlab - Gonzalez Woods & Eddins
Kidney-Tumor-classification-DL-using-MLFlow-CICD Workflows Update config.yaml Update secrets.yaml [Optional] Update params.yaml Update the entity Update the configuration manager in src config Update ...