001package io.ebean.annotation;
002
003import java.lang.annotation.ElementType;
004import java.lang.annotation.Retention;
005import java.lang.annotation.RetentionPolicy;
006import java.lang.annotation.Target;
007
008/**
009 * Specify the default cache use specific entity type.
010 */
011@Target({ElementType.TYPE})
012@Retention(RetentionPolicy.RUNTIME)
013public @interface Cache {
014
015  /**
016   * If set to true additionally use a near cache (for Redis and similar L2 cache options).
017   * <p>
018   * This does not apply to query caches (as they are always near caches) but applies to
019   * the bean caching (bean cache, natural key cache and collection ids cache).
020   * </p>
021   * <p>
022   * Near caches are fast in that they are in local memory avoid going over the network to the
023   * remote cache with the downside of using more local memory and increasing the cache invalidation
024   * costs for updates and deletes (as cache invalidations need to propagate with near caching turned on).
025   * </p>
026   * <p>
027   * Near caching is best with relatively many reads to few writes.
028   * </p>
029   */
030  boolean nearCache() default false;
031
032  /**
033   * Set this to true to enable the use of query cache.
034   * <p>
035   * By default query caching is disabled as the query cache invalidates
036   * frequently and so it is typically used for specific bean types and cases.
037   * </p>
038   */
039  boolean enableQueryCache() default false;
040
041  /**
042   * Set this to false to disable the use of bean cache.
043   * <p>
044   * By default bean caching is expected so this defaults to true.  We might
045   * set this to false on a bean type that we want to use query caching but no
046   * bean caching (and this is expected to be a rare case).
047   * </p>
048   * <p>
049   * When bean caching is enabled by default "find by id" and "find by unique natural key"
050   * queries will try to use the bean cache. We use Query.setUseCache(boolean)
051   * with <code>false</code> for the case when we do NOT want to use the bean cache.
052   * </p>
053   */
054  boolean enableBeanCache() default true;
055
056  /**
057   * Specify the properties that is a natural unique identifier for the bean.
058   * <p>
059   * When a findOne() query is used with this property as the sole expression
060   * then there will be a lookup into the L2 natural key cache.
061   * </p>
062   */
063  String[] naturalKey() default {};
064
065  /**
066   * When set to true the beans returned from a query will default to be
067   * readOnly.
068   * <p>
069   * If the bean is readOnly and has no relationships then it may be sharable.
070   * </p>
071   * <p>
072   * If you try to modify a readOnly bean it will throw an
073   * IllegalStateException.
074   * </p>
075   */
076  boolean readOnly() default false;
077
078  /**
079   * Specify a named cache region.
080   * <p>
081   * Regions can be turned on and off dynamically at runtime.
082   * </p>
083   * <p>
084   * Depending on the cache implementation a region can potentially have different
085   * deployment targets - for example, with the Ebean redis cache a region could be
086   * configured to use a different redis server.
087   * </p>
088   * <p>
089   * The "default" region is called <code>r0</code>.
090   * </p>
091   */
092  String region() default "r0";
093}