@@ -8,7 +8,7 @@ import com.fasterxml.jackson.module.kotlin.KotlinModule
8
8
import com.tairitsu.ignotus.cache.CacheService
9
9
import com.tairitsu.ignotus.support.util.JSON.jsonToObject
10
10
import com.tairitsu.ignotus.support.util.JSON.toJson
11
- import org.springframework.util .DigestUtils
11
+ import org.apache.commons.codec.digest .DigestUtils
12
12
import java.io.File
13
13
import java.nio.file.Files
14
14
import java.nio.file.Paths
@@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap
19
19
import java.util.concurrent.locks.ReentrantLock
20
20
import java.util.function.Supplier
21
21
import kotlin.concurrent.withLock
22
+
22
23
class FilesystemCacheService (storagePath : String ) : CacheService {
23
24
24
25
private val lock = ReentrantLock ()
@@ -89,9 +90,11 @@ class FilesystemCacheService(storagePath: String) : CacheService {
89
90
}
90
91
}
91
92
93
+ private fun String.getMd5 (): String = DigestUtils .md5Hex(this ).lowercase()
94
+
92
95
@Suppress(" DuplicatedCode" )
93
96
private fun getValue (key : String ): CacheEntry ? {
94
- val hash = DigestUtils .md5DigestAsHex( key.toByteArray() )
97
+ val hash = key.getMd5( )
95
98
val path = hash.subSequence(0 , 2 ).toString()
96
99
val file = File (File (baseStoragePath, path), " $hash .json" )
97
100
@@ -116,7 +119,7 @@ class FilesystemCacheService(storagePath: String) : CacheService {
116
119
117
120
@Suppress(" DuplicatedCode" )
118
121
private fun setValue (record : CacheEntry ): Boolean {
119
- val hash = DigestUtils .md5DigestAsHex( record.id.toByteArray() )
122
+ val hash = record.id.getMd5( )
120
123
val path = hash.subSequence(0 , 2 ).toString()
121
124
val folder = File (baseStoragePath, path)
122
125
val file = File (folder, " $hash .json" )
@@ -143,7 +146,7 @@ class FilesystemCacheService(storagePath: String) : CacheService {
143
146
144
147
@Suppress(" DuplicatedCode" )
145
148
private fun delValue (key : String ): CacheEntry ? {
146
- val hash = DigestUtils .md5DigestAsHex( key.toByteArray() )
149
+ val hash = key.getMd5( )
147
150
val path = hash.subSequence(0 , 2 ).toString()
148
151
val file = File (File (baseStoragePath, path), " $hash .json" )
149
152
0 commit comments