April 2003
Beginner to intermediate
380 pages
12h 25m
English
This package contains the classes that can be used to support a hot cache, as presented in Chapter 14.
1 package com.mediamania.hotcache;
2
3 import java.util.Map;
4 import java.util.HashMap;
5
6 import com.mediamania.prototype.PrototypeQueries;
7 import com.mediamania.MediaManiaApp;
8 import com.mediamania.prototype.Movie;
9
10 public abstract class AbstractCache extends MediaManiaApp
11 implements com.mediamania.hotcache.CacheAccess {
12
13 protected Map cache = new HashMap( );
14
15 /** Creates a new instance of AbstractCache. The AbstractCache is the
16 * base class for MasterCache and SlaveCache.
17 */
18 protected AbstractCache( ) {
19 }
20
21 /** Get the Movie by title. If the movie is not in the cache, put it in.
22 * @param title the title of the movie
23 * @return the movie instance
24 */
25 public Movie getMovieByTitle(String title) {
26 Movie movie = (Movie) cache.get(title);
27 if (movie == null) {
28 movie = PrototypeQueries.getMovie (pm, title);
29 if (movie != null) {
30 cache.put (title, movie);
31 }
32 }
33 return movie;
34 }
35 }1 package com.mediamania.hotcache; 2 3 import java.io.InputStream; 4 import java.io.InputStreamReader; 5 import java.io.IOException; 6 import java.io.Reader; 7 import java.io.BufferedReader; 8 9 import java.util.StringTokenizer; 10 11 import java.net.URL; 12 import java.net.MalformedURLException; 13 14 import com.mediamania.Utilities; ...
Read now
Unlock full access