⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blogcache.java

📁 是一个网站的博客系统
💻 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 + -