📄 blogcache.java
字号:
package com.opensource.blog.service.cache.app;
import com.opensource.blog.dao.*;
import com.opensource.blog.model.Blog;
import com.opensource.blog.service.cache.*;
public class BlogCache {
private Cache cache;
private BlogDAO blogDAO;
public BlogCache() {
}
public BlogDAO getBlogDAO() {
return blogDAO;
}
public Cache getCache() {
return cache;
}
public void setBlogDAO(BlogDAO blogDAO) {
this.blogDAO = blogDAO;
}
public void setCache(Cache cache) {
this.cache = cache;
}
public void putInCache(Blog blog) {
this.getCache().add(blog.getUsername(), blog);
}
public Blog getFromCache(String username) {
Blog blog = (Blog)this.getCache().get(username);
if (blog == null) {
blog = this.getBlogDAO().findBlogByUserName(username);
if (blog != null) {
this.putInCache(blog);
}
else {
return null;
}
}
return blog;
}
public void removeFromCache(String username) {
this.getCache().remove(username);
}
public void removeAll() {
this.getCache().removeAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -