Skip to content

Commit

Permalink
Update cache.textile
Browse files Browse the repository at this point in the history
Conflicts:
	documentation/manual/cache.textile
  • Loading branch information
PerfectCarl authored and xael-fry committed Jul 3, 2014
1 parent 4e55b0e commit ad0ffd3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions documentation/manual/cache.textile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ bc. public static void allProducts() {
render(products);
}

p(note). **Modules might configure the cache for you**

For example, the "GAE module":http://www.playframework.com/modules/gae configures the cache to use "Google cache":https://developers.google.com/appengine/docs/java/memcache when deployed to the GAE servers.

h2. <a name="cacheFor">The cacheFor annotation</a>

The @cacheFor@ annotation provides an easy way to cache the ouput (HTML, JSON, etc) of an action.

bc. import play.cache.*;
public class Application extends Controller {
@CacheFor("5s")
public static void indexCachedInSeconds() {
Date date = new Date();
renderText("Current time is: " + date);
}
@CacheFor("1min")
public static void indexCachedInMinutes() {
Date date = new Date();
renderText("Current time is: " + date);
}
}

The annotation takes an optional @duration@ parameter to specify the expiration of the cached content.
The expiration can be specified in days, hours, minutes or seconds using respectively the following shorthands @d@, @h@, @min@ or @s@.

The *default expiration* is @1h@.

p(note). **Using expiration 0s**

When specifying expiration == "0s" (zero seconds) the actual expiration-time may vary between different cache implementations
h2. <a name="api">The cache API</a>

The cache API is provided by the @play.cache.Cache@ class. This class contains the set of methods to set, replace, and get data from the cache. Refer to the Memcached documentation to understand the exact behavior of each method.
Expand Down

0 comments on commit ad0ffd3

Please sign in to comment.