Skip to content

Commit 737a055

Browse files
committed
refactor: 修改依赖
1 parent d411b41 commit 737a055

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

cache/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
compileOnly 'org.springframework.data:spring-data-mongodb:3.3.0'
2323
compileOnly 'org.springframework.boot:spring-boot-autoconfigure:2.5.6'
2424

25+
api 'commons-codec:commons-codec:1.15'
26+
2527
api project(path: ':support')
2628
}
2729

cache/src/main/java/com/tairitsu/ignotus/cache/filesystem/FilesystemCacheService.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.module.kotlin.KotlinModule
88
import com.tairitsu.ignotus.cache.CacheService
99
import com.tairitsu.ignotus.support.util.JSON.jsonToObject
1010
import com.tairitsu.ignotus.support.util.JSON.toJson
11-
import org.springframework.util.DigestUtils
11+
import org.apache.commons.codec.digest.DigestUtils
1212
import java.io.File
1313
import java.nio.file.Files
1414
import java.nio.file.Paths
@@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap
1919
import java.util.concurrent.locks.ReentrantLock
2020
import java.util.function.Supplier
2121
import kotlin.concurrent.withLock
22+
2223
class FilesystemCacheService(storagePath: String) : CacheService {
2324

2425
private val lock = ReentrantLock()
@@ -89,9 +90,11 @@ class FilesystemCacheService(storagePath: String) : CacheService {
8990
}
9091
}
9192

93+
private fun String.getMd5(): String = DigestUtils.md5Hex(this).lowercase()
94+
9295
@Suppress("DuplicatedCode")
9396
private fun getValue(key: String): CacheEntry? {
94-
val hash = DigestUtils.md5DigestAsHex(key.toByteArray())
97+
val hash = key.getMd5()
9598
val path = hash.subSequence(0, 2).toString()
9699
val file = File(File(baseStoragePath, path), "$hash.json")
97100

@@ -116,7 +119,7 @@ class FilesystemCacheService(storagePath: String) : CacheService {
116119

117120
@Suppress("DuplicatedCode")
118121
private fun setValue(record: CacheEntry): Boolean {
119-
val hash = DigestUtils.md5DigestAsHex(record.id.toByteArray())
122+
val hash = record.id.getMd5()
120123
val path = hash.subSequence(0, 2).toString()
121124
val folder = File(baseStoragePath, path)
122125
val file = File(folder, "$hash.json")
@@ -143,7 +146,7 @@ class FilesystemCacheService(storagePath: String) : CacheService {
143146

144147
@Suppress("DuplicatedCode")
145148
private fun delValue(key: String): CacheEntry? {
146-
val hash = DigestUtils.md5DigestAsHex(key.toByteArray())
149+
val hash = key.getMd5()
147150
val path = hash.subSequence(0, 2).toString()
148151
val file = File(File(baseStoragePath, path), "$hash.json")
149152

0 commit comments

Comments
 (0)