Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jenkins
slm-fileview
Commits
cf1ee9c6
Commit
cf1ee9c6
authored
Jun 11, 2019
by
陈精华
Committed by
kl
Jun 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持自动清理预览文件及缓存
parent
13123f8f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
10 deletions
+96
-10
application.properties
jodconverter-web/src/main/conf/application.properties
+2
-0
CacheService.java
...b/src/main/java/cn/keking/service/cache/CacheService.java
+5
-1
CacheServiceJDKImpl.java
...ava/cn/keking/service/cache/impl/CacheServiceJDKImpl.java
+7
-0
CacheServiceRedisImpl.java
...a/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
+22
-0
CacheServiceRocksDBImpl.java
...cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
+26
-0
DeleteFileUtil.java
...ter-web/src/main/java/cn/keking/utils/DeleteFileUtil.java
+11
-5
ShedulerClean.java
...rter-web/src/main/java/cn/keking/utils/ShedulerClean.java
+23
-4
No files found.
jodconverter-web/src/main/conf/application.properties
View file @
cf1ee9c6
...
@@ -27,6 +27,8 @@ spring.http.multipart.max-file-size=100MB
...
@@ -27,6 +27,8 @@ spring.http.multipart.max-file-size=100MB
#redis连接
#redis连接
#spring.redisson.address = 192.168.1.204:6379
#spring.redisson.address = 192.168.1.204:6379
#spring.redisson.password = xxx
#spring.redisson.password = xxx
#缓存自动清理(每晚3点自动清理) true 为开启,注释掉或其他值都为关闭
cache.clean
=
true
#######################################可在运行时动态配置#######################################
#######################################可在运行时动态配置#######################################
#文本类型,默认如下,可自定义添加
#文本类型,默认如下,可自定义添加
...
...
jodconverter-web/src/main/java/cn/keking/service/cache/CacheService.java
View file @
cf1ee9c6
...
@@ -20,7 +20,7 @@ public interface CacheService {
...
@@ -20,7 +20,7 @@ public interface CacheService {
void
initPDFCachePool
(
Integer
capacity
);
void
initPDFCachePool
(
Integer
capacity
);
void
initIMGCachePool
(
Integer
capacity
);
void
initIMGCachePool
(
Integer
capacity
);
public
void
initPdfImagesCachePool
(
Integer
capacity
);
void
initPdfImagesCachePool
(
Integer
capacity
);
void
putPDFCache
(
String
key
,
String
value
);
void
putPDFCache
(
String
key
,
String
value
);
void
putImgCache
(
String
key
,
List
<
String
>
value
);
void
putImgCache
(
String
key
,
List
<
String
>
value
);
Map
<
String
,
String
>
getPDFCache
();
Map
<
String
,
String
>
getPDFCache
();
...
@@ -30,7 +30,11 @@ public interface CacheService {
...
@@ -30,7 +30,11 @@ public interface CacheService {
Integer
getPdfImageCache
(
String
key
);
Integer
getPdfImageCache
(
String
key
);
void
putPdfImageCache
(
String
pdfFilePath
,
int
num
);
void
putPdfImageCache
(
String
pdfFilePath
,
int
num
);
void
cleanCache
();
void
addQueueTask
(
String
url
);
void
addQueueTask
(
String
url
);
String
takeQueueTask
()
throws
InterruptedException
;
String
takeQueueTask
()
throws
InterruptedException
;
}
}
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java
View file @
cf1ee9c6
...
@@ -116,6 +116,13 @@ public class CacheServiceJDKImpl implements CacheService {
...
@@ -116,6 +116,13 @@ public class CacheServiceJDKImpl implements CacheService {
pdfImagesCache
.
put
(
pdfFilePath
,
num
);
pdfImagesCache
.
put
(
pdfFilePath
,
num
);
}
}
@Override
public
void
cleanCache
()
{
initPDFCachePool
(
CacheService
.
DEFAULT_PDF_CAPACITY
);
initIMGCachePool
(
CacheService
.
DEFAULT_IMG_CAPACITY
);
initPdfImagesCachePool
(
CacheService
.
DEFAULT_PDFIMG_CAPACITY
);
}
@Override
@Override
public
void
addQueueTask
(
String
url
)
{
public
void
addQueueTask
(
String
url
)
{
blockingQueue
.
add
(
url
);
blockingQueue
.
add
(
url
);
...
...
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
View file @
cf1ee9c6
...
@@ -94,6 +94,13 @@ public class CacheServiceRedisImpl implements CacheService {
...
@@ -94,6 +94,13 @@ public class CacheServiceRedisImpl implements CacheService {
convertedList
.
fastPut
(
pdfFilePath
,
num
);
convertedList
.
fastPut
(
pdfFilePath
,
num
);
}
}
@Override
public
void
cleanCache
()
{
cleanPdfCache
();
cleanImgCache
();
cleanPdfImgCache
();
}
@Override
@Override
public
void
addQueueTask
(
String
url
)
{
public
void
addQueueTask
(
String
url
)
{
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
...
@@ -105,4 +112,19 @@ public class CacheServiceRedisImpl implements CacheService {
...
@@ -105,4 +112,19 @@ public class CacheServiceRedisImpl implements CacheService {
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
return
queue
.
take
();
return
queue
.
take
();
}
}
private
void
cleanPdfCache
()
{
RMapCache
<
String
,
String
>
pdfCache
=
redissonClient
.
getMapCache
(
REDIS_FILE_PREVIEW_PDF_KEY
);
pdfCache
.
clear
();
}
private
void
cleanImgCache
()
{
RMapCache
<
String
,
List
<
String
>>
imgCache
=
redissonClient
.
getMapCache
(
REDIS_FILE_PREVIEW_IMGS_KEY
);
imgCache
.
clear
();
}
private
void
cleanPdfImgCache
()
{
RMapCache
<
String
,
Integer
>
pdfImg
=
redissonClient
.
getMapCache
(
REDIS_FILE_PREVIEW_PDF_IMGS_KEY
);
pdfImg
.
clear
();
}
}
}
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
View file @
cf1ee9c6
...
@@ -179,6 +179,17 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -179,6 +179,17 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
}
}
}
@Override
public
void
cleanCache
()
{
try
{
cleanPdfCache
();
cleanImgCache
();
cleanPdfImgCache
();
}
catch
(
IOException
|
RocksDBException
e
)
{
LOGGER
.
error
(
"Clean Cache Exception"
+
e
);
}
}
@Override
@Override
public
void
addQueueTask
(
String
url
)
{
public
void
addQueueTask
(
String
url
)
{
blockingQueue
.
add
(
url
);
blockingQueue
.
add
(
url
);
...
@@ -210,4 +221,19 @@ public class CacheServiceRocksDBImpl implements CacheService {
...
@@ -210,4 +221,19 @@ public class CacheServiceRocksDBImpl implements CacheService {
bis
.
close
();
bis
.
close
();
return
obj
;
return
obj
;
}
}
private
void
cleanPdfCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
String
>
initPDFCache
=
new
HashMap
<>();
db
.
put
(
REDIS_FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
initPDFCache
));
}
private
void
cleanImgCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
List
<
String
>>
initIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
initIMGCache
));
}
private
void
cleanPdfImgCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
Integer
>
initPDFIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
initPDFIMGCache
));
}
}
}
jodconverter-web/src/main/java/cn/keking/utils/DeleteFileUtil.java
View file @
cf1ee9c6
package
cn
.
keking
.
utils
;
package
cn
.
keking
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.io.File
;
public
class
DeleteFileUtil
{
public
class
DeleteFileUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DeleteFileUtil
.
class
);
/**
/**
* 删除单个文件
* 删除单个文件
*
*
...
@@ -15,14 +21,14 @@ public class DeleteFileUtil {
...
@@ -15,14 +21,14 @@ public class DeleteFileUtil {
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
if
(
file
.
exists
()
&&
file
.
isFile
())
{
if
(
file
.
exists
()
&&
file
.
isFile
())
{
if
(
file
.
delete
())
{
if
(
file
.
delete
())
{
System
.
out
.
println
(
"删除单个文件"
+
fileName
+
"成功!"
);
LOGGER
.
info
(
"删除单个文件"
+
fileName
+
"成功!"
);
return
true
;
return
true
;
}
else
{
}
else
{
System
.
out
.
println
(
"删除单个文件"
+
fileName
+
"失败!"
);
LOGGER
.
info
(
"删除单个文件"
+
fileName
+
"失败!"
);
return
false
;
return
false
;
}
}
}
else
{
}
else
{
System
.
out
.
println
(
"删除单个文件失败:"
+
fileName
+
"不存在!"
);
LOGGER
.
info
(
"删除单个文件失败:"
+
fileName
+
"不存在!"
);
return
false
;
return
false
;
}
}
}
}
...
@@ -43,7 +49,7 @@ public class DeleteFileUtil {
...
@@ -43,7 +49,7 @@ public class DeleteFileUtil {
File
dirFile
=
new
File
(
dir
);
File
dirFile
=
new
File
(
dir
);
// 如果dir对应的文件不存在,或者不是一个目录,则退出
// 如果dir对应的文件不存在,或者不是一个目录,则退出
if
((!
dirFile
.
exists
())
||
(!
dirFile
.
isDirectory
()))
{
if
((!
dirFile
.
exists
())
||
(!
dirFile
.
isDirectory
()))
{
System
.
out
.
println
(
"删除目录失败:"
+
dir
+
"不存在!"
);
LOGGER
.
info
(
"删除目录失败:"
+
dir
+
"不存在!"
);
return
false
;
return
false
;
}
}
boolean
flag
=
true
;
boolean
flag
=
true
;
...
@@ -65,7 +71,7 @@ public class DeleteFileUtil {
...
@@ -65,7 +71,7 @@ public class DeleteFileUtil {
}
}
}
}
if
(!
flag
)
{
if
(!
flag
)
{
System
.
out
.
println
(
"删除目录失败!"
);
LOGGER
.
info
(
"删除目录失败!"
);
return
false
;
return
false
;
}
}
return
true
;
return
true
;
...
...
jodconverter-web/src/main/java/cn/keking/utils/ShedulerClean.java
View file @
cf1ee9c6
package
cn
.
keking
.
utils
;
package
cn
.
keking
.
utils
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.service.cache.CacheService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
/**
* @auther: chenjh
* @since: 2019/6/11 7:45
*/
@Component
@Component
@ConditionalOnExpression
(
"'${cache.clean:false}'.equals('true')"
)
public
class
ShedulerClean
{
public
class
ShedulerClean
{
String
fileDir
=
ConfigConstants
.
getFileDir
();
// @Scheduled(cron = "0 0 23 * * ?") //每晚23点执行一次
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ShedulerClean
.
class
);
public
void
clean
(){
System
.
out
.
println
(
"执行一次清空文件夹"
);
@Autowired
private
CacheService
cacheService
;
private
String
fileDir
=
ConfigConstants
.
getFileDir
();
@Scheduled
(
cron
=
"0 0 3 * * ?"
)
//每晚3点执行一次
public
void
clean
()
{
LOGGER
.
info
(
"Cache clean start"
);
cacheService
.
cleanCache
();
DeleteFileUtil
.
deleteDirectory
(
fileDir
);
DeleteFileUtil
.
deleteDirectory
(
fileDir
);
LOGGER
.
info
(
"Cache clean end"
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment