001package com.avaje.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   * Set this to true to enable the use of query cache.
017   * <p>
018   * By default query caching is disabled as the query cache invalidates
019   * frequently and so it is typically used for specific bean types and cases.
020   * </p>
021   */
022  boolean enableQueryCache() default false;
023
024  /**
025   * Set this to false to disable the use of bean cache.
026   * <p>
027   * By default bean caching is expected so this defaults to true.  We might
028   * set this to false on a bean type that we want to use query caching but no
029   * bean caching (and this is expected to be a rare case).
030   * </p>
031   * <p>
032   * When bean caching is enabled by default "find by id" and "find by unique natural key"
033   * queries will try to use the bean cache. We use {@link com.avaje.ebean.Query#setUseCache(boolean)}
034   * with <code>false</code> for the case when we do NOT want to use the bean cache.
035   * </p>
036   */
037  boolean enableBeanCache() default true;
038
039  /**
040   * Specify the property that is a natural unique identifier for the bean.
041   * <p>
042   * When a findUnique() query is used with this property as the sole expression
043   * then there will be a lookup into the L2 natural key cache.
044   * </p>
045   */
046  String naturalKey() default "";
047
048  /**
049   * When set to true the beans returned from a query will default to be
050   * readOnly.
051   * <p>
052   * If the bean is readOnly and has no relationships then it may be sharable.
053   * </p>
054   * <p>
055   * If you try to modify a readOnly bean it will throw an
056   * IllegalStateException.
057   * </p>
058   */
059  boolean readOnly() default false;
060
061}