Skip to content

Commit 6db1ff5

Browse files
authored
[jacodb-storage, jacodb-core] Move pluggable caches to jacodb-storage (#304)
Pluggable caches API moved to the jacodb-storage-api module, implementations are in the jacodb-storage module. The jacodb-storage module has compileOnly dependencies on the libraries providing caches. So to use caches without dependency on the jacodb-core module, one should define particular dependency of the caching library, Guava or Xodus.
1 parent f66dd8c commit 6db1ff5

File tree

11 files changed

+30
-30
lines changed

11 files changed

+30
-30
lines changed

jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/Settings.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.jacodb.api.jvm
1818

1919
import kotlinx.collections.immutable.persistentListOf
2020
import kotlinx.collections.immutable.toPersistentList
21+
import org.jacodb.api.caches.ValueStoreType
2122
import java.io.File
2223
import java.time.Duration
2324

@@ -186,8 +187,6 @@ data class JcCacheSegmentSettings(
186187
val expiration: Duration = Duration.ofMinutes(1)
187188
)
188189

189-
enum class ValueStoreType { WEAK, SOFT, STRONG }
190-
191190
class JcCacheSettings {
192191
var cacheSpiId: String? = null
193192
var classes: JcCacheSegmentSettings = JcCacheSegmentSettings()

jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCacheProvider.kt renamed to jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCacheProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.jacodb.impl.caches
17+
package org.jacodb.api.caches
1818

1919
import org.jacodb.api.spi.CommonSPI
2020
import org.jacodb.api.spi.SPILoader

jacodb-core/src/main/kotlin/org/jacodb/impl/caches/PluggableCaches.kt renamed to jacodb-api-storage/src/main/kotlin/org/jacodb/api/caches/PluggableCaches.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.jacodb.impl.caches
17+
package org.jacodb.api.caches
1818

19-
import org.jacodb.api.jvm.ValueStoreType
2019
import java.time.Duration
2120

21+
enum class ValueStoreType { WEAK, SOFT, STRONG }
22+
2223
class PluggableCacheException(message: String) : RuntimeException(message)
2324

2425
interface PluggableCache<K : Any, V : Any> {

jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/caches/PluggableCacheBenchmarks.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.jacodb.testing.performance.caches
1818

1919
import kotlinx.benchmark.Blackhole
20-
import org.jacodb.api.jvm.ValueStoreType
21-
import org.jacodb.impl.caches.PluggableCache
20+
import org.jacodb.api.caches.PluggableCache
21+
import org.jacodb.api.caches.ValueStoreType
2222
import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID
2323
import org.openjdk.jmh.annotations.Benchmark
2424
import org.openjdk.jmh.annotations.BenchmarkMode

jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/ClasspathCache.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package org.jacodb.impl.features.classpaths
1818

1919
import mu.KLogging
20+
import org.jacodb.api.caches.PluggableCache
21+
import org.jacodb.api.caches.PluggableCacheProvider
22+
import org.jacodb.api.caches.PluggableCacheStats
2023
import org.jacodb.api.jvm.JcCacheSegmentSettings
2124
import org.jacodb.api.jvm.JcCacheSettings
2225
import org.jacodb.api.jvm.JcClassType
@@ -35,9 +38,6 @@ import org.jacodb.api.jvm.cfg.JcInst
3538
import org.jacodb.api.jvm.cfg.JcInstList
3639
import org.jacodb.api.jvm.cfg.JcRawInst
3740
import org.jacodb.api.jvm.ext.JAVA_OBJECT
38-
import org.jacodb.impl.caches.PluggableCache
39-
import org.jacodb.impl.caches.PluggableCacheProvider
40-
import org.jacodb.impl.caches.PluggableCacheStats
4141
import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID
4242
import org.jacodb.impl.features.classpaths.AbstractJcInstResult.JcFlowGraphResultImpl
4343
import org.jacodb.impl.features.classpaths.AbstractJcInstResult.JcInstListResultImpl

jacodb-core/src/main/kotlin/org/jacodb/impl/storage/AbstractJcDbPersistence.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.jacodb.impl.storage
1818

19+
import org.jacodb.api.caches.PluggableCache
20+
import org.jacodb.api.caches.PluggableCacheProvider
1921
import org.jacodb.api.jvm.JcByteCodeLocation
2022
import org.jacodb.api.jvm.JcDatabasePersistence
2123
import org.jacodb.api.jvm.RegisteredLocation
2224
import org.jacodb.api.storage.ers.getEntityOrNull
23-
import org.jacodb.impl.caches.PluggableCache
24-
import org.jacodb.impl.caches.PluggableCacheProvider
2525
import org.jacodb.impl.caches.xodus.XODUS_CACHE_PROVIDER_ID
2626
import org.jacodb.impl.fs.JavaRuntime
2727
import org.jacodb.impl.fs.asByteCodeLocation
@@ -73,7 +73,7 @@ abstract class AbstractJcDbPersistence(
7373
).mapNotNull {
7474
try {
7575
File(it.path).asByteCodeLocation(javaRuntime.version, isRuntime = it.runtime)
76-
} catch (e: Exception) {
76+
} catch (_: Exception) {
7777
null
7878
}
7979
}.flatten().distinct()
@@ -131,7 +131,7 @@ abstract class AbstractJcDbPersistence(
131131
override fun close() {
132132
try {
133133
symbolInterner.close()
134-
} catch (e: Exception) {
134+
} catch (_: Exception) {
135135
// ignore
136136
}
137137
}

jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/caches/PluggableCacheTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.jacodb.testing.caches
1818

19-
import org.jacodb.impl.caches.PluggableCache
19+
import org.jacodb.api.caches.PluggableCache
2020
import org.junit.jupiter.api.Assertions.assertEquals
2121
import org.junit.jupiter.api.Assertions.assertTrue
2222
import org.junit.jupiter.api.BeforeEach

jacodb-storage/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ dependencies {
44
compileOnly(Libs.xodusEnvironment)
55
compileOnly(Libs.lmdb_java)
66
compileOnly(Libs.rocks_db)
7-
7+
compileOnly(Libs.guava)
8+
compileOnly(Libs.xodusUtils)
89

910
testImplementation(Libs.xodusEnvironment)
1011
testImplementation(Libs.lmdb_java)

jacodb-core/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt renamed to jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/guava/GuavaCaches.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ package org.jacodb.impl.caches.guava
1818

1919
import com.google.common.cache.Cache
2020
import com.google.common.cache.CacheBuilder
21-
import org.jacodb.api.jvm.ValueStoreType
22-
import org.jacodb.impl.caches.PluggableCache
23-
import org.jacodb.impl.caches.PluggableCacheBuilder
24-
import org.jacodb.impl.caches.PluggableCacheProvider
25-
import org.jacodb.impl.caches.PluggableCacheStats
26-
import java.time.Duration
21+
import org.jacodb.api.caches.PluggableCache
22+
import org.jacodb.api.caches.PluggableCacheBuilder
23+
import org.jacodb.api.caches.PluggableCacheProvider
24+
import org.jacodb.api.caches.PluggableCacheStats
25+
import org.jacodb.api.caches.ValueStoreType
2726

2827
const val GUAVA_CACHE_PROVIDER_ID = "org.jacodb.impl.caches.guava.GuavaCacheProvider"
2928

@@ -42,7 +41,7 @@ private class GuavaCacheBuilder<K : Any, V : Any> : PluggableCacheBuilder<K, V>(
4241
.maximumSize(maximumSize.toLong())
4342
.apply {
4443
expirationDuration.let {
45-
if (it != Duration.ZERO) {
44+
if (it != java.time.Duration.ZERO) {
4645
expireAfterAccess(it)
4746
}
4847
}

jacodb-core/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt renamed to jacodb-storage/src/main/kotlin/org/jacodb/impl/caches/xodus/XodusCaches.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package org.jacodb.impl.caches.xodus
1919
import jetbrains.exodus.core.dataStructures.ConcurrentObjectCache
2020
import jetbrains.exodus.core.dataStructures.ObjectCacheBase
2121
import jetbrains.exodus.core.dataStructures.SoftConcurrentObjectCache
22-
import org.jacodb.api.jvm.ValueStoreType
23-
import org.jacodb.impl.caches.PluggableCache
24-
import org.jacodb.impl.caches.PluggableCacheBuilder
25-
import org.jacodb.impl.caches.PluggableCacheException
26-
import org.jacodb.impl.caches.PluggableCacheProvider
27-
import org.jacodb.impl.caches.PluggableCacheStats
22+
import org.jacodb.api.caches.PluggableCache
23+
import org.jacodb.api.caches.PluggableCacheBuilder
24+
import org.jacodb.api.caches.PluggableCacheException
25+
import org.jacodb.api.caches.PluggableCacheProvider
26+
import org.jacodb.api.caches.PluggableCacheStats
27+
import org.jacodb.api.caches.ValueStoreType
2828

2929
const val XODUS_CACHE_PROVIDER_ID = "org.jacodb.impl.caches.xodus.XodusCacheProvider"
3030

@@ -51,7 +51,7 @@ private class XodusCacheBuilder<K : Any, V : Any> : PluggableCacheBuilder<K, V>(
5151
}
5252

5353
/**
54-
* Generally, Xodus' [ObjectCacheBase] is not synchronized, but [XodusCacheBuilder] creates
54+
* Generally, Xodus' [jetbrains.exodus.core.dataStructures.ObjectCacheBase] is not synchronized, but [XodusCacheBuilder] creates
5555
* its "concurrent" implementations which do not require synchronization. If this ever changes,
5656
* [XodusCache] should be synchronized.
5757
*/

0 commit comments

Comments
 (0)