zoukankan      html  css  js  c++  java
  • flowable 图片缓存

    背景

    由于我们的每次显示图片的话,都将需要大量的查询和相关的流。这样对我们的系统压力极大,用户体验极差。

    所以使用了缓存把图片流缓存起来,这样就可以解决问题了。

    实现

    这里我用的是ehcache,由于他小巧依赖少。

    1:把我们的包导入进来

    <!--开启 cache 缓存-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-cache</artifactId>
            </dependency>
            <!-- ehcache 缓存 -->
            <dependency>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache</artifactId>
            </dependency>

    2:配置xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
             updateCheck="false">
        <diskStore path="/data/flow/ehcache"/>
        <defaultCache
                eternal="false"
                maxElementsInMemory="900"
                overflowToDisk="false"
                diskPersistent="false"
                timeToIdleSeconds="0"
                timeToLiveSeconds="30"
                memoryStoreEvictionPolicy="LRU"/>
        <!-- 这里的 cache-process-image 缓存流程的图片信息 -->
        <cache
                name="cache-process-image"
                eternal="false"
                maxElementsInMemory="2000"
                maxElementsOnDisk="3000"
                overflowToDisk="true"
                diskPersistent="true"
                timeToIdleSeconds="0"
                timeToLiveSeconds="1296000"
                memoryStoreEvictionPolicy="LRU"/>
    </ehcache>

    3:配置application.properties文件

    spring.cache.ehcache.config=classpath:/ehcache/flow-ehcache.xml

    4:配置缓存注解

    @Cacheable(value = FlowConstant.CACHE_PROCESS_IMAGE, key = "'" + FlowConstant.PROCESSINSTANCE_PREFIX + "'+ #processDefinitionId
    ") public byte[] createImage(String processDefinitionId
    ) {

    就这么简单就能实现图片缓存了,以廉价的技术实现强大的功能。

  • 相关阅读:
    c.vim
    Ubuntu18.04重装指南
    [TJOI2017]城市 【树的直径+暴力+优化】
    [Bzoj3696]化合物【暴力+树形Dp】
    [JLOI2015]战争调度【暴力+树形Dp】
    [Bzoj3743][Coci2015] Kamp【换根Dp】
    [POI2017]Sabota【观察+树形Dp】
    [CQOI2009]叶子的染色【性质+树形Dp】
    COCI2014/2015 Contest#1 D MAFIJA【基环树最大独立点集】
    [牛客网] 推箱子【离散,线段树区间覆盖】
  • 原文地址:https://www.cnblogs.com/liuwenjun/p/10325331.html
Copyright © 2011-2022 走看看