Ehcache-上手

3 Getting Started(上手)
......................................................................................................................................
3.1 Getting Started
Firstly, if you have not downloaded Ehcache, you can download it here.
Ehcache can be used directly. It can also be used with the popular Hibernate Object/Relational tool.
Finally, it can be used for Java EE Servlet Caching.
This quick guide gets you started on each of these. The rest of the documentation can be explored for

a deeper understanding.

==================================翻译=========================================

首先,如果你还没有下载ehcahe,你可以从这边下载。。。

Ehcache可以直接被使用。它也可以被用作流行的hibernate 对象/关系 工具已经javaEE servlet缓存。

这是个手册能让你快速的学习上面的这些东西。如果你想有更深入的了解,可以阅读剩余的文档。


3.1.1 General Purpose Caching

• Make sure you are using a supported Java version.
• Place the Ehcache jar into your classpath.
• Ensure that any libraries required to satisfy dependencies are also in the classpath.
• Configure ehcache.xml and place it in your classpath.
• Optionally, configure an appropriate logging level.

See the Code Samples chapter for more information on direct interaction with ehcache.

==================================翻译=========================================

搭建一般目的的缓存

l 确定你正在使用可支持的JAVA版本
l 将ehcache的jar包加入到类路径
l 确保任何依赖的库在类路径中
l 配置ehcache.xml文件并且将它放置在你的类路径,(备注:其实只要能读取到就可以了)
l 可选项:配置一个合适的日志级别

查看Code Sample章节了解更多信息。


3.1.2 Hibernate
• Perform the same steps as for General Purpose Caching.
• Create caches in ehcache.xml.

See the Hibernate Caching chapter for more information.

==================================翻译=========================================

Hibernate
l 执行和General Purpose Caching 相同的步骤,
l 在ehcache.xml文件里创建缓存
查看Hibernate Caching 章节了解更多的信息。


3.1.3 Distributed Caching
Ehcache supports distributed caching with two lines of configuration.
• Download the ehcache-distribution package.
• Add ehcache-core jar to your classpath
• Add ehcache-terracotta jar to your classpath
• Add a 'terracotta' element to your 'cache' stanza(s) in ehcache.xml
• Add a 'terracottaConfig' element to your 'ehcache' stanza in ehcache.xml.

• See the Distributed Caching With Terracotta chapter for more information.

==================================翻译=========================================

分布式缓存

Ehcache可以通过两种方式来支持分布式缓存

|下载ehcache-distribution包

|将ehcache-core jar包加入classpath

|将ehcache-terractotta jar包加入classpaht

|将terracotta元素加到ehcache.xml中的cache节点

|将terracottaConfig元素加到ehcache.xml中的ehcache节点

查看Distributed Caching With Terracotta 章节了解更多的信息。


(备注:这边说两种方法,但是这边列表中只列出了通过terracotta搭建分布式缓存,其实另外一种方式是通过RMI来实现。RMI是javaSE中自带,所以不需要依赖其他额外的包)


3.1.4 Java EE Servlet Caching
• Perform the same steps as for General Purpose Caching.
• Configure a cache for your web page in ehcache.xml.
• To cache an entire web page, either use SimplePageCachingFilter or create your own subclass of
CachingFilter
• To cache a jsp:Include or anything callable from a RequestDispatcher, either use
SimplePageFragmentCachingFilter or create a subclass of PageFragmentCachingFilter.
• Configure the web.xml. Declare the filters created above and create filter mapping associating
the filter with a URL.
See the Web Caching chapter for more information.

==================================翻译=========================================

Java EE Servlet缓存

l 执行和General Purpose Caching 相同的步骤,

l 在ehcache.xml文件里为你的网页配置一个缓存

l 缓存整个web页面,使用SimplePageCachingFilter类或者创建自己的CachingFilter子类。

l 缓存JSP文件:包含的或任何来自RequestDispatcher的请求,无论是使用SimplePageFragmentCachingFilter或创建一个PageFragmentCachingFilter的子类。 
| 配置web.xml。声明上述建立的过滤器并创建过滤器映射关联的URL。

查看Web Caching 章节了解更多的信息。



3.1.5 RESTful and SOAP Caching with the Cache Server
• Download the ehcache-standalone-server from https://sourceforge.net/projects/ehcache/files/
ehcache-server.
• cd to the bin directory
• Type startup.sh to start the server with the log in the foreground.
By default it will listen on port 8080, will have both RESTful and SOAP web services enabled,
and will use a sample Ehcache configuration from the WAR module.
• See the code samples in the Cache Server chapter. You can use Java or any other programming
language to the use the Cache Server.

See the Cache Server chapter for more information.

==================================翻译=========================================

通过缓存服务器来缓存RESTful和SOAP

l 从https://sourceforge.net/projects/ehcache/files/ehcache-server.下载独立的缓存服务器
l 进入bin目录
l 键入startup.sh以日志的形式启动服务器
l 服务默认是在8080端口监听,RESTful 和 SOAP的网络服务都是可用的,使用来自WAR模块里一个简单的Ehcache配置。
| 查看Cache Server 章节的代码示例,你可以使用java或者任何其它的编程语言来使用缓存服务器。
查看Cache Server 章节了解更多信息




3.1.6 JCache style caching
Ehcache contains an early draft implementation of JCache contained in the net.sf.ehcache.jcache
package.

See the JSR107 chapter for usage.

==================================翻译=========================================

Jcache形式的缓存

Ehcache 包含了一个早期粗略的JCache实现,该实现在net.sf.ehcache.jcache包中。

使用方法请查看JSR107章节。


3.1.7 Spring, Cocoon, Acegi and other frameworks
Usually, with these, you are using Ehcache without even realising it. The first steps in getting more
control over what is happening are:
• discover the cache names used by the framework

• create your own ehcache.xml with settings for the caches and place it in the application classpath.

==================================翻译=========================================

Spring, Cocoon, Acegi 和其他框架

 通常,在使用这些框架的时候,你甚至没有意识到你正在使用ehcache。第一步是通过什么正在发生获取更多控制:

l 发现被框架使用缓存名字

l 为缓存创建你自己的ehcache.xml文件配置,并且将该文件放置到应用程序的类路径中。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值