{"action":"opened","issue":{"url":"https://api.github.com/repos/playframework-ja/translation-project/issues/1279","repository_url":"https://api.github.com/repos/playframework-ja/translation-project","labels_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/1279/labels{/name}","comments_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/1279/comments","events_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/1279/events","html_url":"https://github.com/playframework-ja/translation-project/issues/1279","id":132184612,"number":1279,"title":"manual/working/scalaGuide/main/cache/ScalaCache.md","user":{"login":"garbagetown","id":78121,"avatar_url":"https://avatars.githubusercontent.com/u/78121?v=3","gravatar_id":"","url":"https://api.github.com/users/garbagetown","html_url":"https://github.com/garbagetown","followers_url":"https://api.github.com/users/garbagetown/followers","following_url":"https://api.github.com/users/garbagetown/following{/other_user}","gists_url":"https://api.github.com/users/garbagetown/gists{/gist_id}","starred_url":"https://api.github.com/users/garbagetown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garbagetown/subscriptions","organizations_url":"https://api.github.com/users/garbagetown/orgs","repos_url":"https://api.github.com/users/garbagetown/repos","events_url":"https://api.github.com/users/garbagetown/events{/privacy}","received_events_url":"https://api.github.com/users/garbagetown/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/playframework-ja/translation-project/labels/update","name":"update","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/playframework-ja/translation-project/milestones/17","html_url":"https://github.com/playframework-ja/translation-project/milestones/2.4.x","labels_url":"https://api.github.com/repos/playframework-ja/translation-project/milestones/17/labels","id":1568709,"number":17,"title":"2.4.x","description":"","creator":{"login":"garbagetown","id":78121,"avatar_url":"https://avatars.githubusercontent.com/u/78121?v=3","gravatar_id":"","url":"https://api.github.com/users/garbagetown","html_url":"https://github.com/garbagetown","followers_url":"https://api.github.com/users/garbagetown/followers","following_url":"https://api.github.com/users/garbagetown/following{/other_user}","gists_url":"https://api.github.com/users/garbagetown/gists{/gist_id}","starred_url":"https://api.github.com/users/garbagetown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garbagetown/subscriptions","organizations_url":"https://api.github.com/users/garbagetown/orgs","repos_url":"https://api.github.com/users/garbagetown/repos","events_url":"https://api.github.com/users/garbagetown/events{/privacy}","received_events_url":"https://api.github.com/users/garbagetown/received_events","type":"User","site_admin":false},"open_issues":138,"closed_issues":0,"state":"open","created_at":"2016-02-07T14:54:37Z","updated_at":"2016-02-08T16:12:16Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2016-02-08T16:12:16Z","updated_at":"2016-02-08T16:12:16Z","closed_at":null,"body":"- https://github.com/playframework-ja/translation-project/tree//2.4.x/manual/working/scalaGuide/main/cache/ScalaCache.md\n- diffs between [2.2.0/manual/working/scalaGuide/main/cache/ScalaCache.md](https://github.com/playframework-ja/translation-project/tree//2.2.0/manual/working/scalaGuide/main/cache/ScalaCache.md) and [2.4.x/manual/working/scalaGuide/main/cache/ScalaCache.md](https://github.com/playframework-ja/translation-project/tree//2.4.x/manual/working/scalaGuide/main/cache/ScalaCache.md).\n```\n--- /Users/garbagetown/Desktop/2.2.0/manual/working/scalaGuide/main/cache/ScalaCache.md\t2016-02-07 23:19:03.000000000 +0900\n+++ //Users/garbagetown/Desktop/2.4.x/manual/working/scalaGuide/main/cache/ScalaCache.md\t2016-02-07 23:19:30.000000000 +0900\n@@ -1,18 +1,37 @@\n+<!--- Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com> -->\n # The Play cache API\n \n-The default implementation of the Cache API uses [EHCache](http://ehcache.org/). You can also provide your own implementation via a plug-in.\n+Caching data is a typical optimization in modern applications, and so Play provides a global cache.\n+\n+> An important point about the cache is that it behaves just like a cache should: the data you just stored may just go missing.\n+\n+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. \n+\n+The default implementation of the Cache API uses [EHCache](http://ehcache.org/).\n+\n+## Importing the Cache API\n+\n+Add `cache` into your dependencies list. For example, in `build.sbt`:\n+\n+'''scala\n+libraryDependencies ++= Seq(\n+  cache,\n+  ...\n+)\n+'''\n \n ## Accessing the Cache API\n \n-The cache API is provided by the `play.api.cache.Cache` object. It requires a registered cache plug-in.\n+The cache API is provided by the [CacheApi](api/scala/play/api/cache/CacheApi.html) object, and can be injected into your component like any other dependency.  For example:\n+\n+@[inject](code/ScalaCache.scala)\n \n-> **Note:** The API is intentionally minimal to allow several implementation to be plugged. If you need a more specific API, use the one provided by your Cache plugin.\n+> **Note:** The API is intentionally minimal to allow several implementation to be plugged in. If you need a more specific API, use the one provided by your Cache plugin.\n \n Using this simple API you can either store data in cache:\n \n @[set-value](code/ScalaCache.scala)\n \n-\n And then retrieve it later:\n \n @[get-value](code/ScalaCache.scala)\n@@ -21,26 +40,66 @@\n \n @[retrieve-missing](code/ScalaCache.scala)\n \n+You can specify an expiry duration by passing a duration, by default the duration is infinite:\n+\n+@[set-value-expiration](code/ScalaCache.scala)\n \n To remove an item from the cache use the `remove` method:\n \n @[remove-value](code/ScalaCache.scala)\n \n+## Accessing different caches\n+\n+It is possible to access different caches.  The default cache is called `play`, and can be configured by creating a file called `ehcache.xml`.  Additional caches may be configured with different configurations, or even implementations.\n+\n+If you want to access multiple different ehcache caches, then you'll need to tell Play to bind them in `application.conf`, like so:\n+\n+    play.cache.bindCaches = [\"db-cache\", \"user-cache\", \"session-cache\"]\n+\n+Now to access these different caches, when you inject them, use the [NamedCache](api/java/play/cache/NamedCache.html) qualifier on your dependency, for example:\n+\n+@[qualified](code/ScalaCache.scala)\n \n ## Caching HTTP responses\n \n-You can easily create smart cached actions using standard Action composition. \n+You can easily create smart cached actions using standard Action composition.\n \n > **Note:** Play HTTP `Result` instances are safe to cache and reuse later.\n \n-Play provides a default built-in helper for standard cases:\n+The [Cached](api/scala/play/api/cache/Cached.html) class helps you build cached actions.\n \n-@[cached-action](code/ScalaCache.scala)\n+@[cached-action-app](code/ScalaCache.scala)\n+\n+You can cache the result of an action using a fixed key like `\"homePage\"`.\n \n+@[cached-action](code/ScalaCache.scala)\n \n-Or even:\n+If results vary, you can cache each result using a different key. In this example, each user has a different cached result.\n \n @[composition-cached-action](code/ScalaCache.scala)\n \n+### Control caching\n+\n+You can easily control what you want to cache or what you want to exclude from the cache.\n+\n+You may want to only cache 200 Ok results.\n+\n+@[cached-action-control](code/ScalaCache.scala)\n+\n+Or cache 404 Not Found only for a couple of minutes\n+\n+@[cached-action-control-404](code/ScalaCache.scala)\n+\n+## Custom implementations\n+\n+It is possible to provide a custom implementation of the [CacheApi](api/scala/play/api/cache/CacheApi.html) that either replaces, or sits along side the default implementation.\n+\n+To replace the default implementation, you'll need to disable the default implementation by setting the following in `application.conf`:\n+\n+'''\n+play.modules.disabled += \"play.api.cache.EhCacheModule\"\n+'''\n+\n+Then simply implement `CacheApi` and bind it in the [[DI container|ScalaDependencyInjection]].\n \n-> **Next:** [[Calling web services | ScalaWS]]\n+To provide an implementation of the cache API in addition to the default implementation, you can either create a custom qualifier, or reuse the `NamedCache` qualifier to bind the implementation.\n\n```"}}