Skip to content

Commit

Permalink
JT-78303: Add license; Refactor package
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-zatsepin committed Jan 10, 2024
1 parent 08e69b6 commit ca5bef3
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import jetbrains.exodus.core.cache.CaffeineCacheConfig
import jetbrains.exodus.core.cache.FixedSizeEviction
import jetbrains.exodus.core.cache.SizeEviction
import jetbrains.exodus.core.cache.WeightSizeEviction
import jetbrains.exodus.core.dataStructures.cache.CaffeinePersistentCache
import jetbrains.exodus.core.dataStructures.cache.PersistentCache
import jetbrains.exodus.core.cache.CaffeinePersistentCache
import jetbrains.exodus.core.cache.PersistentCache
import jetbrains.exodus.entitystore.iterate.CachedInstanceIterable
import java.time.Duration

Expand Down
19 changes: 17 additions & 2 deletions utils/src/main/kotlin/jetbrains/exodus/core/cache/BasicCache.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package jetbrains.exodus.core.dataStructures.cache
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import java.util.function.BiConsumer

Expand All @@ -23,7 +38,7 @@ interface BasicCache<K, V> {
/**
* Store value in cache by key.
*/
fun put(key: K, v: V)
fun put(key: K, value: V)

/**
* Invalidate value by key if present.
Expand Down
20 changes: 17 additions & 3 deletions utils/src/main/kotlin/jetbrains/exodus/core/cache/CaffeineCache.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import com.github.benmanes.caffeine.cache.Cache
import jetbrains.exodus.core.dataStructures.cache.BasicCache
import java.util.function.BiConsumer

class CaffeineCache<K, V>(
Expand Down Expand Up @@ -36,8 +50,8 @@ class CaffeineCache<K, V>(
return cache.getIfPresent(key)
}

override fun put(key: K, v: V) {
cache.put(key, v)
override fun put(key: K, value: V) {
cache.put(key, value)
}

override fun remove(key: K) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import com.github.benmanes.caffeine.cache.Weigher

internal object CaffeineCacheBuilder {

Expand Down Expand Up @@ -35,11 +49,11 @@ internal object CaffeineCacheBuilder {

is WeightSizeEviction -> {
maximumWeight(sizeEviction.maxWeight)
weigher(Weigher { key: K, value: V ->
weigher { key: K, value: V ->
@Suppress("UNCHECKED_CAST")
val key = keyTransformer?.invoke(key) ?: (key as ConfigK)
sizeEviction.weigher(key, value)
})
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import java.time.Duration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package jetbrains.exodus.core.dataStructures.cache
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import com.github.benmanes.caffeine.cache.Weigher
import jetbrains.exodus.core.cache.CaffeineCacheBuilder
import jetbrains.exodus.core.cache.CaffeineCacheConfig
import jetbrains.exodus.core.cache.FixedSizeEviction
import jetbrains.exodus.core.cache.WeightSizeEviction
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
import java.util.function.BiConsumer
import kotlin.collections.forEach


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package jetbrains.exodus.core.dataStructures.cache
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.cache

import java.util.function.BiConsumer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/*
* Copyright ${inceptionYear} - ${year} ${owner}
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.core.dataStructures.cache

import jetbrains.exodus.core.cache.CaffeineCacheConfig
import jetbrains.exodus.core.cache.CaffeinePersistentCache
import jetbrains.exodus.core.cache.FixedSizeEviction
import jetbrains.exodus.core.cache.WeightSizeEviction
import org.junit.Assert.assertEquals
Expand Down

0 comments on commit ca5bef3

Please sign in to comment.