一直以来懒得配置缓存,基本的缓存也就是orm层,基本上都交给hibernate去配置了。这段时间,感觉页面速度太慢了,还是需要使用缓存。现在的缓存工具也挺多的,较不错的属ehcache和oscache了。决定分别研究一下。
先来说说ehcache,目前的版本为1.2,已经支持集群了。对于ehcache的使用,感觉很容易上手,基本上都是配置。以前在hibernate的时候配置过,所以也不是很陌生。API也挺简单,如下的api:
CacheManager主要的缓存管理类,一般一个应用为一个实例,如下
CacheManager.create();也可以使用new CacheManager的方式创建
默认的配置文件为ehcache.xml文件,也可以使用不同的配置:
java 代码
-
- CacheManager manager = new CacheManager("src/config/other.xml");
缓存的创建,采用自动的方式
java 代码
-
- CacheManager singletonManager = CacheManager.create();
- singletonManager.addCache("testCache");
- Cache test = singletonManager.getCache("testCache");
或者直接创建Cache
java 代码
-
- CacheManager singletonManager = CacheManager.create();
- Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
- manager.addCache(memoryOnlyCache);
- Cache test = singletonManager.getCache("testCache");
删除cache
java 代码
- CacheManager singletonManager = CacheManager.create();
- singletonManager.removeCache("sampleCache1");
在使用ehcache后,需要关闭
java 代码
- CacheManager.getInstance().shutdown()
-
- caches 的使用
-
- Cache cache = manager.getCache("sampleCache1");
执行crud操作
java 代码
- Cache cache = manager.getCache("sampleCache1");
- Element element = new Element("key1", "value1");
- cache.put(element);
-
- update
-
- Cache cache = manager.getCache("sampleCache1");
- cache.put(new Element("key1", "value1");
-
- cache.put(new Element("key1", "value2");
-
- get Serializable
-
- Cache cache = manager.getCache("sampleCache1");
- Element element = cache.get("key1");
- Serializable value = element.getValue();
-
- get non serializable
-
- Cache cache = manager.getCache("sampleCache1");
- Element element = cache.get("key1");
- Object value = element.getObjectValue();
-
- remove
-
- Cache cache = manager.getCache("sampleCache1");
- Element element = new Element("key1", "value1"
- cache.remove("key1");
不过缓存还是基本上以配置方式为主,下一篇文章将会说明ehcache如何配置
Cache本身的配置可以在代码中更改吗?
比如:timeToIdleSeconds想要修改。
根据用户输入的数值进行修改。
只能是 new Cache(...)来操作?
|
需要高性能、可靠的集群缓存
可否给推荐几个
最好是稳定、性能、社区都很好的.呵.
分享到:
相关推荐
ehcache3-samples, 关于使用 Ehcache 3,一些示例/教程 Ehcache示例这里知识库包含有关 Ehcache 3用法的示例和教程。示例'basic'演示 Ehcache 3的基本配置和用法'集群'- 演示如何在Terracotta服务器上使用分布式缓存...
shiro-demo使用ehcache做缓存.zip
在Spring+Hibernate集成环境中使用EhCache缓存做的开发测试,在线程中打开数据库查询数据,及关闭数据库后查询数据的结果.
springboot2.0使用ehcache缓存,这个压缩包时一个简单的demo。
当有数据更新的时候,每个进程中的缓存都是独立维护的,如果这些进程缓存同步机制,那么就存在因缓存没有...所以,本文就来说说当使用EhCache的时候,如果来组建进程内缓存EnCache的集群以及配置配置他们的同步策略。
Spring Boot中使用EhCache实现缓存支持,介绍整合方法和配置
NULL 博文链接:https://cuisuqiang.iteye.com/blog/2050675
Ehcache使用: CacheManager主要的缓存管理类,一般一个应用为一个实例,如下 CacheManager.create();也可以使用new CacheManager的方式创建 默认的配置文件为ehcache.xml文件,也可以使用不同的配置: ...
EhCache 是一个纯 Java 的进程内缓存框架,具有快速、精干等特点,是 Hibernate 中默认的 CacheProvider。这篇文章主要介绍了SpringBoot中使用Ehcache的相关知识,需要的朋友可以参考下
使用ehcahe时自己做的工具类,方便以后使用
ehcache使用例子,maven项目。
【EhCache】Java缓存框架使用EhCache结合Spring AOP EhCache是一个纯Java的进程内缓存框架,具有如下特点: 1. 快速简单,非常容易和应用集成。 2.支持多种缓存策略 。 3. 缓存数据有两级:内存和磁盘,因此无需...
本篇文章主要介绍了SpringBoot手动使用EhCache的方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
主要介绍了Spring Boot如何使用EhCache演示,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
ehcache的依赖包,使用ehcache缓存机制必备
。。。
简单介绍Ehcache的优缺点
NULL 博文链接:https://cczakai.iteye.com/blog/1622708
Ehcache 的一个简单demo案例 了解如何使用ehcache 以及掌握一些基本的api
主要介绍了spring使用ehcache实现页面缓存示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧