View Javadoc

1   /*
2    *  Copyright 2004 David C. Brown
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.ashkay;
17  
18  
19  
20  
21  /***
22   * CachingStrategies provide abstract strategies about how a cache ought to
23   * perform its caching. When an object is added to the cache, the
24   * CachingStrategy is asked to prepare the CacheEntry for that object. The
25   * CachingStrategy may return a new Entry that serves its purposes better, or
26   * may just set a few properties on the current entry.
27   * <br><br>
28   * When the object is looked up in the cache, the CachingStrategy is asked to
29   * validate this object, if the validation fails for any strategy, the object is
30   * reloaded.
31   *
32   * @author <a href="mailto:bangroot@users.sf.net">Dave Brown</a>
33   */
34  public interface CachingStrategy {
35  
36      /***
37       * Prepares the cache entry for caching with this strategy.<br>
38       * <b>NOTE:</b> Be Careful: a caching strategy <em>is</em> allowed to return
39       * a different CacheEntry, so make sure that you store the results of this
40       * method and don't assume the symantics of pass by reference.
41       */
42      public abstract CacheEntry prepare(CacheEntry entry);
43  
44      /***
45       * Validates this cache entry for this caching strategy.
46       */
47      public abstract boolean validate(CacheEntry entry);
48  }