mirror of https://github.com/halo-dev/halo
👽 测试Ehcache
parent
129106a2ae
commit
6e7f7172d4
5
pom.xml
5
pom.xml
|
@ -92,6 +92,11 @@
|
||||||
<version>${druid.version}</version>
|
<version>${druid.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-cache</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- freemarker依赖 -->
|
<!-- freemarker依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author RYAN0UP
|
* @author RYAN0UP
|
||||||
|
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableCaching
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.io.Serializable;
|
||||||
@Data
|
@Data
|
||||||
public class Theme implements Serializable {
|
public class Theme implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主题名称
|
* 主题名称
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Link;
|
||||||
import cc.ryanc.halo.repository.LinkRepository;
|
import cc.ryanc.halo.repository.LinkRepository;
|
||||||
import cc.ryanc.halo.service.LinkService;
|
import cc.ryanc.halo.service.LinkService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -19,6 +21,10 @@ public class LinkServiceImpl implements LinkService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LinkRepository linkRepository;
|
private LinkRepository linkRepository;
|
||||||
|
|
||||||
|
private static final String LINKS_CACHE_KEY = "'link'";
|
||||||
|
|
||||||
|
private static final String LINKS_CACHE_NAME = "links";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增/修改友情链接
|
* 新增/修改友情链接
|
||||||
*
|
*
|
||||||
|
@ -26,6 +32,7 @@ public class LinkServiceImpl implements LinkService {
|
||||||
* @return Link
|
* @return Link
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(value = LINKS_CACHE_NAME, key = LINKS_CACHE_KEY)
|
||||||
public Link saveByLink(Link link) {
|
public Link saveByLink(Link link) {
|
||||||
return linkRepository.save(link);
|
return linkRepository.save(link);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +44,7 @@ public class LinkServiceImpl implements LinkService {
|
||||||
* @return Link
|
* @return Link
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(value = LINKS_CACHE_NAME, key = LINKS_CACHE_KEY)
|
||||||
public Link removeByLinkId(Long linkId) {
|
public Link removeByLinkId(Long linkId) {
|
||||||
Optional<Link> link = this.findByLinkId(linkId);
|
Optional<Link> link = this.findByLinkId(linkId);
|
||||||
linkRepository.delete(link.get());
|
linkRepository.delete(link.get());
|
||||||
|
@ -49,6 +57,7 @@ public class LinkServiceImpl implements LinkService {
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Cacheable(value = LINKS_CACHE_NAME, key = LINKS_CACHE_KEY)
|
||||||
public List<Link> findAllLinks() {
|
public List<Link> findAllLinks() {
|
||||||
return linkRepository.findAll();
|
return linkRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import cc.ryanc.halo.model.domain.Menu;
|
||||||
import cc.ryanc.halo.repository.MenuRepository;
|
import cc.ryanc.halo.repository.MenuRepository;
|
||||||
import cc.ryanc.halo.service.MenuService;
|
import cc.ryanc.halo.service.MenuService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -19,12 +21,17 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MenuRepository menuRepository;
|
private MenuRepository menuRepository;
|
||||||
|
|
||||||
|
private static final String MENUS_CACHE_KEY = "'menu'";
|
||||||
|
|
||||||
|
private static final String MENUS_CACHE_NAME = "menus";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有菜单
|
* 查询所有菜单
|
||||||
*
|
*
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Cacheable(value = MENUS_CACHE_NAME, key = MENUS_CACHE_KEY)
|
||||||
public List<Menu> findAllMenus() {
|
public List<Menu> findAllMenus() {
|
||||||
return menuRepository.findAll();
|
return menuRepository.findAll();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +43,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
* @return Menu
|
* @return Menu
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(value = MENUS_CACHE_NAME, key = MENUS_CACHE_KEY)
|
||||||
public Menu saveByMenu(Menu menu) {
|
public Menu saveByMenu(Menu menu) {
|
||||||
return menuRepository.save(menu);
|
return menuRepository.save(menu);
|
||||||
}
|
}
|
||||||
|
@ -47,6 +55,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
* @return Menu
|
* @return Menu
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(value = MENUS_CACHE_NAME,key = MENUS_CACHE_KEY)
|
||||||
public Menu removeByMenuId(Long menuId) {
|
public Menu removeByMenuId(Long menuId) {
|
||||||
Optional<Menu> menu = this.findByMenuId(menuId);
|
Optional<Menu> menu = this.findByMenuId(menuId);
|
||||||
menuRepository.delete(menu.get());
|
menuRepository.delete(menu.get());
|
||||||
|
|
|
@ -16,10 +16,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.imageio.ImageReadParam;
|
|
||||||
import javax.imageio.ImageReader;
|
|
||||||
import javax.imageio.stream.ImageInputStream;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -36,7 +32,6 @@ import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -57,34 +52,6 @@ public class HaloUtils {
|
||||||
|
|
||||||
private static ArrayList<String> FILE_LIST = new ArrayList<>();
|
private static ArrayList<String> FILE_LIST = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 截取图片
|
|
||||||
*
|
|
||||||
* @param src 输入路径
|
|
||||||
* @param dest 输出路径
|
|
||||||
* @param w 宽度
|
|
||||||
* @param h 长度
|
|
||||||
* @param suffix 后缀
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void cutCenterImage(String src, String dest, int w, int h, String suffix) {
|
|
||||||
try {
|
|
||||||
Iterator iterator = ImageIO.getImageReadersByFormatName(suffix);
|
|
||||||
ImageReader reader = (ImageReader) iterator.next();
|
|
||||||
InputStream in = new FileInputStream(src);
|
|
||||||
ImageInputStream iis = ImageIO.createImageInputStream(in);
|
|
||||||
reader.setInput(iis, true);
|
|
||||||
ImageReadParam param = reader.getDefaultReadParam();
|
|
||||||
int imageIndex = 0;
|
|
||||||
Rectangle rect = new Rectangle((reader.getWidth(imageIndex) - w) / 2, (reader.getHeight(imageIndex) - h) / 2, w, h);
|
|
||||||
param.setSourceRegion(rect);
|
|
||||||
BufferedImage bi = reader.read(0, param);
|
|
||||||
ImageIO.write(bi, suffix, new File(dest));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("剪裁失败,图片本身尺寸小于需要修剪的尺寸:{0}", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有附件
|
* 获取所有附件
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,12 +24,9 @@ import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
|
||||||
|
updateCheck="false">
|
||||||
|
|
||||||
|
<defaultCache
|
||||||
|
eternal="false"
|
||||||
|
maxElementsInMemory="1000"
|
||||||
|
overflowToDisk="false"
|
||||||
|
diskPersistent="false"
|
||||||
|
timeToIdleSeconds="0"
|
||||||
|
timeToLiveSeconds="600"
|
||||||
|
memoryStoreEvictionPolicy="LRU"/>
|
||||||
|
|
||||||
|
<cache
|
||||||
|
name="links"
|
||||||
|
eternal="false"
|
||||||
|
maxElementsInMemory="100"
|
||||||
|
overflowToDisk="false"
|
||||||
|
diskPersistent="false"
|
||||||
|
timeToIdleSeconds="0"
|
||||||
|
timeToLiveSeconds="300"
|
||||||
|
memoryStoreEvictionPolicy="LRU"/>
|
||||||
|
|
||||||
|
<cache
|
||||||
|
name="menus"
|
||||||
|
eternal="false"
|
||||||
|
maxElementsInMemory="20"
|
||||||
|
overflowToDisk="false"
|
||||||
|
diskPersistent="false"
|
||||||
|
timeToIdleSeconds="0"
|
||||||
|
timeToLiveSeconds="300"
|
||||||
|
memoryStoreEvictionPolicy="LRU"/>
|
||||||
|
</ehcache>
|
Loading…
Reference in New Issue