-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCache.java
45 lines (35 loc) · 1.39 KB
/
Cache.java
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
42
43
44
45
package cz.cvut.fel.adaptiverestfulapi.caching;
import cz.cvut.fel.adaptiverestfulapi.core.HttpContext;
import cz.cvut.fel.adaptiverestfulapi.core.Filter;
import cz.cvut.fel.adaptiverestfulapi.core.FilterException;
import cz.cvut.fel.adaptiverestfulapi.meta.configuration.Configuration;
import cz.cvut.fel.adaptiverestfulapi.meta.model.Model;
/**
* Abstract class for cache support.
*/
public abstract class Cache extends Filter {
@Override
public HttpContext process(HttpContext httpContext, Model model, Configuration configuration) throws FilterException {
if (this.load(httpContext, model, configuration)) { // try load data from cache
return httpContext;
}
httpContext = this.resign(httpContext, model, configuration); // ask for data someone else
this.save(httpContext, model, configuration); // finally save new data to cache
return httpContext;
}
/**
* Load data from the cache.
* @param httpContext
* @param model
* @param configuration
* @return true if hit was made
*/
protected abstract boolean load(HttpContext httpContext, Model model, Configuration configuration);
/**
* Save data to the cache.
* @param httpContext
* @param model
* @param configuration
*/
protected abstract void save(HttpContext httpContext, Model model, Configuration configuration);
}