我有缓存列表,我的代码看起来像这样
public class MyList {
private final List<String> cache = new ArrayList<String>();
private List<String> loadMyList() {
// HEAVY OPERATION TO LOAD DATA
}
public List<String> list() {
synchronized (cache) {
if( cache.size() == 0 ) {
cache.addAll(loadMyList());
}
return Collections.unmodifiableList(cache);
}
}
public void invalidateCache() {
synchronized (cache) {
cache.clear();
}
}
}
Run Code Online (Sandbox Code Playgroud)
因为列表加载非常繁重,我收到一个请求,如果列表加载当前正在进行中,则返回"旧"缓存数据...
这是可能的,有人可以指点我如何从这里开始
编辑:亚当Horvath和bayou.io sugested这样的东西
public class MyList
{
private final List<String> cache = new ArrayList<String>();
private final List<String> oldCache = new ArrayList<String>();
private volatile boolean loadInProgress = …Run Code Online (Sandbox Code Playgroud) 目前,我的页面上有很多后退按钮:
<input type="button" id="Back" value="Back" onclick="back();" class="backButton">
Run Code Online (Sandbox Code Playgroud)
我需要添加图标以使其看起来像这样:
提前谢谢。