Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
mchernyakov committed Dec 23, 2019
1 parent a3eaae6 commit 813a3f5
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Various time to live cache
# Various time to live map

[![Build Status](https://travis-ci.com/mchernyakov/various-ttl-cache.svg?branch=master)](https://travis-ci.com/mchernyakov/various-ttl-cache)
[![Build Status](https://travis-ci.com/mchernyakov/various-ttl-map.svg?branch=master)](https://travis-ci.com/mchernyakov/various-ttl-map)

## Description

Tiny library with various ttl cache. Based on Redis expire [algorithm](https://redis.io/commands/expire).
Tiny library with various ttl map. Based on Redis expire [algorithm](https://redis.io/commands/expire).

The implementation contains two maps:
1) keys and values,
Expand Down Expand Up @@ -39,7 +39,7 @@ Builder properties:

#### In code
```java
VariousTtlCache<String, String> map = VariousTtlCacheImpl.Builder.newBuilder()
VariousTtlMap<String, String> map = VariousTtlMapImpl.Builder.newBuilder()
.setDefaultTtl(2)
.setCleaningPoolSize(2)
.setNumCleaningAttemptsPerSession(250)
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'various-ttl-cache'
rootProject.name = 'various-ttl-map'

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.mchernyakov.variousttlcache;
package com.github.mchernyakov.variousttlmap;

import com.github.mchernyakov.variousttlcache.util.Preconditions;
import com.github.mchernyakov.variousttlcache.util.ThreadUtil;
import com.github.mchernyakov.variousttlmap.util.Preconditions;
import com.github.mchernyakov.variousttlmap.util.ThreadUtil;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -32,14 +32,14 @@ class BackgroundMapCleaner<K, V> {
private static final int RED_LINE_PERCENT = 90;

private final ScheduledExecutorService executorService;
private final VariousTtlCacheImpl<K, V> map;
private final VariousTtlMapImpl<K, V> map;

private final long delayTime;
private final int poolSize;
private final int numKeyCheck;
private final int percentWaterMark;

private BackgroundMapCleaner(VariousTtlCacheImpl<K, V> variousTtlMap, Builder<K, V> builder) {
private BackgroundMapCleaner(VariousTtlMapImpl<K, V> variousTtlMap, Builder<K, V> builder) {
Preconditions.checkArgument(builder.poolSize > 0);
Preconditions.checkArgument(builder.numKeyCheck > 0);
Preconditions.checkArgument(builder.delayTime > 0);
Expand Down Expand Up @@ -176,7 +176,7 @@ public Builder<K, V> setPercentWaterMark(int percentWaterMark) {

@SuppressWarnings("unchecked")
public <K1 extends K, V1 extends V>
BackgroundMapCleaner<K1, V1> build(@NotNull VariousTtlCacheImpl<K1, V1> map) {
BackgroundMapCleaner<K1, V1> build(@NotNull VariousTtlMapImpl<K1, V1> map) {
Preconditions.checkNotNull(map);
Builder<K1, V1> self = (Builder<K1, V1>) this;
return new BackgroundMapCleaner<>(map, self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.mchernyakov.variousttlcache;
package com.github.mchernyakov.variousttlmap;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface VariousTtlCache<K, V> {
public interface VariousTtlMap<K, V> {

@Nullable
V get(K key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.mchernyakov.variousttlcache;
package com.github.mchernyakov.variousttlmap;

import com.github.mchernyakov.variousttlcache.applied.PrimitiveMapWrapper;
import com.github.mchernyakov.variousttlcache.util.Preconditions;
import com.github.mchernyakov.variousttlmap.applied.PrimitiveMapWrapper;
import com.github.mchernyakov.variousttlmap.util.Preconditions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -10,20 +10,20 @@
import java.util.concurrent.TimeUnit;

/**
* The Cache with various ttl for keys.
* The Map with various ttl for keys.
* <p>
* This implementation contains 2 maps :
* 1) store (key + value) {@link VariousTtlCacheImpl#store},
* 2) map for ttl (key + ttl (when keys will be expired)) {@link VariousTtlCacheImpl#ttlMap}.
* 1) store (key + value) {@link VariousTtlMapImpl#store},
* 2) map for ttl (key + ttl (when keys will be expired)) {@link VariousTtlMapImpl#ttlMap}.
* <p>
* This implementation has two variants of cleaning:
* 1) passive via {@link VariousTtlCacheImpl#get(K)},
* 1) passive via {@link VariousTtlMapImpl#get(K)},
* 2) active via {@link BackgroundMapCleaner}.
*
* @param <K> key
* @param <V> value
*/
public class VariousTtlCacheImpl<K, V> implements VariousTtlCache<K, V> {
public class VariousTtlMapImpl<K, V> implements VariousTtlMap<K, V> {

private final ConcurrentHashMap<K, V> store;
private final PrimitiveMapWrapper ttlMap;
Expand All @@ -32,7 +32,7 @@ public class VariousTtlCacheImpl<K, V> implements VariousTtlCache<K, V> {
private final long defaultTtl;
private final TimeUnit timeUnit = TimeUnit.SECONDS;

private VariousTtlCacheImpl(Builder<K, V> builder) {
private VariousTtlMapImpl(Builder<K, V> builder) {
Preconditions.checkArgument(builder.defaultTtl > 0);

defaultTtl = timeUnit.toNanos(builder.defaultTtl);
Expand Down Expand Up @@ -112,7 +112,7 @@ public void shutdown() {

@Override
public String toString() {
return "VariousTtlCacheImpl{" +
return "VariousTtlMapImpl{" +
"store=" + store +
", ttlMap=" + ttlMap +
", mapCleaner=" + mapCleaner +
Expand Down Expand Up @@ -161,9 +161,9 @@ public Builder<K, V> setDelayMillis(int delayMillis) {
}

@SuppressWarnings("unchecked")
public <K1 extends K, V1 extends V> VariousTtlCacheImpl<K1, V1> build() {
public <K1 extends K, V1 extends V> VariousTtlMapImpl<K1, V1> build() {
Builder<K1, V1> self = (Builder<K1, V1>) this;
return new VariousTtlCacheImpl<>(self);
return new VariousTtlMapImpl<>(self);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mchernyakov.variousttlcache.applied;
package com.github.mchernyakov.variousttlmap.applied;

import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mchernyakov.variousttlcache.util;
package com.github.mchernyakov.variousttlmap.util;


import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mchernyakov.variousttlcache.util;
package com.github.mchernyakov.variousttlmap.util;

import java.util.Locale;
import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mchernyakov.variousttlcache.util;
package com.github.mchernyakov.variousttlmap.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.mchernyakov.variousttlcache;
package com.github.mchernyakov.variousttlmap;

import org.junit.After;
import org.junit.Assert;
Expand All @@ -9,12 +9,12 @@

public class BackgroundMapCleanerTest {

private VariousTtlCacheImpl<String, String> mapClassic;
private VariousTtlMapImpl<String, String> mapClassic;
private BackgroundMapCleaner<String, String> mapCleaner;

@Before
public void setUp() throws Exception {
mapClassic = VariousTtlCacheImpl.Builder.newBuilder()
mapClassic = VariousTtlMapImpl.Builder.newBuilder()
.setDefaultTtl(2)
.setCleaningPoolSize(1)
.setNumCleaningAttemptsPerSession(20)
Expand Down Expand Up @@ -54,7 +54,7 @@ public void basicTest1() throws Exception {

@Test
public void basicTest2() throws Exception {
VariousTtlCache<String, String> mapClassic = VariousTtlCacheImpl.Builder.newBuilder()
VariousTtlMap<String, String> mapClassic = VariousTtlMapImpl.Builder.newBuilder()
.setDefaultTtl(2)
.setCleaningPoolSize(2)
.setNumCleaningAttemptsPerSession(250)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.mchernyakov.variousttlcache;
package com.github.mchernyakov.variousttlmap;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class VariousTtlCacheImplTest {
public class VariousTtlMapImplTest {

@Test(expected = Exception.class)
public void conditionTest() throws Exception {
Expand Down

0 comments on commit 813a3f5

Please sign in to comment.