BlogCache.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
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();
- }
- }