forked from ReactiveDesignPatterns/CodeSamples
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathImageServiceController.java
More file actions
41 lines (34 loc) · 886 Bytes
/
ImageServiceController.java
File metadata and controls
41 lines (34 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2018 https://www.reactivedesignpatterns.com/
*
* Copyright (c) 2018 https://rdp.reactiveplatform.xyz/
*
*/
import java.awt.*;
import java.awt.image.BufferedImage;
// Listing 2.1 Excerpt from a simple controller for an image service
public class ImageServiceController {
private static final Image FALLBACK = new BufferedImage(100, 100, BufferedImage.TYPE_INT_BGR);
// #snip
public interface Images {
Image get(String key);
void add(String key, Image image);
}
private Images cache;
private Images database;
public Image retrieveImages(String key) {
Image result = cache.get(key);
if (result != null) {
return result;
} else {
result = database.get(key);
if (result != null) {
cache.add(key, result);
return result;
} else {
return FALLBACK;
}
}
}
// #snip
}