garbagetown/playdocja — pull request #554 by wm3 (2014-03-12 16:34:25+00:00)
Title: manual/javaGuide/main/cache/JavaCache.md

- https://github.com/garbagetown/playdocja/blob/2.2.0/documentation/2.2.0/manual/javaGuide/main/cache/JavaCache.md
```
--- /Users/garbagetown/Desktop/2.1.5/manual/javaGuide/main/cache/JavaCache.md	2013-09-19 22:53:02.000000000 +0900
+++ /Users/garbagetown/Desktop/2.2.0/manual/javaGuide/main/cache/JavaCache.md	2013-09-19 10:11:22.000000000 +0900
@@ -4,7 +4,7 @@

For any data stored in the cache, a regeneration strategy needs to be put in place in case the data goes missing. This philosophy is one of the fundamentals behind Play, and is different from Java EE, where the session is expected to retain values throughout its lifetime.

-The default implementation of the cache API uses [[EHCache| http://www.ehcache.org/]] and it's enabled by default. You can also provide your own implementation via a plugin.
+The default implementation of the cache API uses [EHCache](http://www.ehcache.org/) and it's enabled by default. You can also provide your own implementation via a plugin.

## Accessing the Cache API
@@ -15,30 +15,19 @@

Using this simple API you can store data in the cache:

-'''
-Cache.set("item.key", frontPageNews);
-'''
+@[simple-set](code/javaguide/cache/JavaCache.java)

Optionally you can specify a expiration (in seconds) for the cache:

-'''
-// Cache for 15 minutes
-Cache.set("item.key", frontPageNews, 60 * 15);
-'''
+@[time-set](code/javaguide/cache/JavaCache.java)

You can retrieve the data later:

-'''
-News news = Cache.get("item.key");
-'''
-
+@[get](code/javaguide/cache/JavaCache.java)

To remove an item from the cache use the `remove` method:

-'''
-Cache.remove("item.key")
-'''
-
+@[remove](code/javaguide/cache/JavaCache.java)

## Caching HTTP responses

@@ -48,43 +37,6 @@

Play provides a default built-in helper for the standard case:

-'''
-@Cached("homePage")
-public static Result index() {
- return ok("Hello world");
-}
-'''
-
-## Caching in templates
-
-You may also access the cache from a view template.
-
-'''
-@cache.Cache.getOrElse("cached-content", 3600) {
-

I’m cached for an hour

-}
-'''
-
-## Session cache
-
-Play provides a global cache, whose data are visible to anybody. How would one restrict visibility to a given user? For instance you may want to cache metrics that only apply to a given user.
-
-
-'''
-// Generate a unique ID
-String uuid=session("uuid");
-if(uuid==null) {
-	uuid=java.util.UUID.randomUUID().toString();
-	session("uuid", uuid);
-}
-
-// Access the cache
-News userNews = Cache.get(uuid+"item.key");
-if(userNews==null) {
-	userNews = generateNews(uuid);
-	Cache.set(uuid+"item.key", userNews );
-}
-'''
-
+@[http](code/javaguide/cache/JavaCache.java)

> **Next:** [[Calling web services | JavaWS]]

```