Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / EntityCacheConfig.java
blob0cce522b9eac6e4e1e81355954df58f8c7677a7a
1 package com.google.appengine.api.datastore;
3 import static com.google.common.base.Preconditions.checkNotNull;
5 /**
6 * Specifies the entity cache configuration for the datastore service.
7 * <p>
8 * The default entity cache configuration values for an {@code EntityCacheConfig} instance are
9 * a memcache backed entity cache, {@link EntityCachingCriteria#ALL_KEYS} for the caching criteria,
10 * and {@link EntityCachePolicy#CACHE} for the caching policy.
11 * <p>
12 * See {@link DatastoreServiceConfig#entityCacheConfig} for details on how to specify an
13 * {@code EntityCacheConfig} to enable caching of datastore entities when using the
14 * datastore service.
16 final class EntityCacheConfig {
18 private EntityCachingCriteria entityCachingCriteria = EntityCachingCriteria.ALL_KEYS;
19 private EntityCachePolicy entityCachePolicy = EntityCachePolicy.CACHE;
21 /**
22 * Sets the {@link EntityCachingCriteria}.
24 * @param entityCachingCriteria the {@link EntityCachingCriteria} to use to determine if an entity
25 * should be cached.
26 * @return {@code this} (for chaining)
28 public EntityCacheConfig entityCachingCriteria(EntityCachingCriteria entityCachingCriteria) {
29 this.entityCachingCriteria =
30 checkNotNull(entityCachingCriteria, "The entityCachingCriteria argument can not be null");
31 return this;
34 /**
35 * @return the {@link EntityCachingCriteria} specified in this entity cache configuration.
37 public EntityCachingCriteria getEntityCachingCriteria() {
38 return entityCachingCriteria;
41 /**
42 * Sets the {@link EntityCachePolicy}.
44 * @param entityCachePolicy the {@link EntityCachePolicy} to use for entity caching.
45 * @return {@code this} (for chaining)
47 public EntityCacheConfig entityCachePolicy(EntityCachePolicy entityCachePolicy) {
48 this.entityCachePolicy =
49 checkNotNull(entityCachePolicy, "The entityCachePolicy argument can not be null");
50 return this;
53 /**
54 * @return the {@link EntityCachePolicy} specified in this entity cache configuration.
56 public EntityCachePolicy getEntityCachePolicy() {
57 return entityCachePolicy;
60 private EntityCacheConfig() {
63 /**
64 * Contains static creation methods for {@link EntityCacheConfig} instances.
66 public static final class Builder {
68 /**
69 * Create an {@link EntityCacheConfig} instance with the specified
70 * {@code entityCachingCriteria} and with the default configuration values for all other fields.
72 * @param entityCachingCriteria the {@link EntityCachingCriteria} to use to determine if an
73 * entity should be cached.
74 * @return the newly created EntityCacheConfig instance.
76 public static EntityCacheConfig withEntityCachingCriteria(
77 EntityCachingCriteria entityCachingCriteria) {
78 return withDefaults().entityCachingCriteria(entityCachingCriteria);
81 /**
82 * Create an {@link EntityCacheConfig} instance with the specified {@code entityCachePolicy} and
83 * with the default configuration values for all other fields.
85 * @param entityCachePolicy the {@link EntityCachePolicy} to use for entity caching.
86 * @return the newly created EntityCacheConfig instance.
88 public static EntityCacheConfig withEntityCachePolicy(EntityCachePolicy entityCachePolicy) {
89 return withDefaults().entityCachePolicy(entityCachePolicy);
92 /**
93 * Create an {@link EntityCacheConfig} instance with the default configuration values.
95 * @return the newly created EntityCacheConfig instance.
97 public static EntityCacheConfig withDefaults() {
98 return new EntityCacheConfig();
101 private Builder() {}