Annotation Type Cache


@Target(TYPE) @Retention(RUNTIME) public @interface Cache
Specify the default cache use specific entity type.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Set this to false to disable the use of bean cache.
    boolean
    Set this to true to enable the use of query cache.
    Specify the properties that is a natural unique identifier for the bean.
    boolean
    If set to true additionally use a near cache (for Redis and similar L2 cache options).
    boolean
    When set to true the beans returned from a query will default to be readOnly.
    Specify a named cache region.
  • Element Details

    • nearCache

      boolean nearCache
      If set to true additionally use a near cache (for Redis and similar L2 cache options).

      This does not apply to query caches (as they are always near caches) but applies to the bean caching (bean cache, natural key cache and collection ids cache).

      Near caches are fast in that they are in local memory avoid going over the network to the remote cache with the downside of using more local memory and increasing the cache invalidation costs for updates and deletes (as cache invalidations need to propagate with near caching turned on).

      Near caching is best with relatively many reads to few writes.

      Default:
      false
    • enableQueryCache

      boolean enableQueryCache
      Set this to true to enable the use of query cache.

      By default query caching is disabled as the query cache invalidates frequently and so it is typically used for specific bean types and cases.

      Default:
      false
    • enableBeanCache

      boolean enableBeanCache
      Set this to false to disable the use of bean cache.

      By default bean caching is expected so this defaults to true. We might set this to false on a bean type that we want to use query caching but no bean caching (and this is expected to be a rare case).

      When bean caching is enabled by default "find by id" and "find by unique natural key" queries will try to use the bean cache. We use Query.setUseCache(boolean) with false for the case when we do NOT want to use the bean cache.

      Default:
      true
    • naturalKey

      String[] naturalKey
      Specify the properties that is a natural unique identifier for the bean.

      When a findOne() query is used with this property as the sole expression then there will be a lookup into the L2 natural key cache.

      Default:
      {}
    • readOnly

      boolean readOnly
      When set to true the beans returned from a query will default to be readOnly.

      If the bean is readOnly and has no relationships then it may be sharable.

      If you try to modify a readOnly bean it will throw an IllegalStateException.

      Default:
      false
    • region

      String region
      Specify a named cache region.

      Regions can be turned on and off dynamically at runtime.

      Depending on the cache implementation a region can potentially have different deployment targets - for example, with the Ebean redis cache a region could be configured to use a different redis server.

      The "default" region is called r0.

      Default:
      "r0"