Skip to content

Commit 92e6d18

Browse files
committed
refactor: Move cache code to own project: cactoos-cache
1 parent be66bd2 commit 92e6d18

35 files changed

Lines changed: 174 additions & 1610 deletions

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<artifactId>cactoos</artifactId>
8787
<version>0.57.0</version>
8888
</dependency>
89+
<dependency>
90+
<groupId>com.github.fabriciofx</groupId>
91+
<artifactId>cactoos-cache</artifactId>
92+
<version>0.0.1</version>
93+
</dependency>
8994
<dependency>
9095
<groupId>com.zaxxer</groupId>
9196
<artifactId>HikariCP</artifactId>

src/main/java/com/github/fabriciofx/cactoos/jdbc/Cache.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/java/com/github/fabriciofx/cactoos/jdbc/cache/CacheEntry.java

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
*/
55
package com.github.fabriciofx.cactoos.jdbc.cache;
66

7+
import com.github.fabriciofx.cactoos.cache.Key;
8+
import com.github.fabriciofx.cactoos.cache.entry.EntryEnvelope;
79
import com.github.fabriciofx.cactoos.jdbc.Query;
810
import com.github.fabriciofx.cactoos.jdbc.Table;
9-
import java.util.HashSet;
11+
import java.util.List;
1012
import java.util.Map;
1113
import java.util.Set;
1214
import org.cactoos.Scalar;
15+
import org.cactoos.list.ListOf;
1316
import org.cactoos.map.MapEntry;
1417
import org.cactoos.map.MapOf;
1518
import org.cactoos.scalar.Unchecked;
@@ -18,22 +21,7 @@
1821
* CacheEntry.
1922
* @since 0.9.0
2023
*/
21-
public final class CacheEntry implements Entry<Query, Table> {
22-
/**
23-
* Key.
24-
*/
25-
private final Key<Query> id;
26-
27-
/**
28-
* Table to be stored in the cache.
29-
*/
30-
private final Table table;
31-
32-
/**
33-
* Metadata (tables names).
34-
*/
35-
private final Map<String, Set<String>> meta;
36-
24+
public final class CacheEntry extends EntryEnvelope<Query, Table> {
3725
/**
3826
* Ctor.
3927
* @param key The key
@@ -51,7 +39,7 @@ public CacheEntry(
5139
new MapOf<>(
5240
new MapEntry<>(
5341
"tables",
54-
new Unchecked<>(tables).value()
42+
new ListOf<>(new Unchecked<>(tables).value())
5543
)
5644
)
5745
);
@@ -60,31 +48,14 @@ public CacheEntry(
6048
/**
6149
* Ctor.
6250
* @param key The key
63-
* @param table The table to be stored
64-
* @param meta Metadata associated with this entry.
51+
* @param table The Table
52+
* @param metadata Metadata (table names)
6553
*/
6654
public CacheEntry(
6755
final Key<Query> key,
6856
final Table table,
69-
final Map<String, Set<String>> meta
57+
final Map<String, List<String>> metadata
7058
) {
71-
this.id = key;
72-
this.table = table;
73-
this.meta = meta;
74-
}
75-
76-
@Override
77-
public Key<Query> key() {
78-
return this.id;
79-
}
80-
81-
@Override
82-
public Table value() {
83-
return this.table;
84-
}
85-
86-
@Override
87-
public Iterable<String> metadata(final String entity) {
88-
return this.meta.getOrDefault(entity, new HashSet<>());
59+
super(key, table, metadata);
8960
}
9061
}

src/main/java/com/github/fabriciofx/cactoos/jdbc/cache/CacheKey.java

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,20 @@
44
*/
55
package com.github.fabriciofx.cactoos.jdbc.cache;
66

7+
import com.github.fabriciofx.cactoos.cache.key.KeyEnvelope;
78
import com.github.fabriciofx.cactoos.jdbc.Query;
8-
import com.github.fabriciofx.cactoos.jdbc.cache.hash.Murmur3Hash;
99
import com.github.fabriciofx.cactoos.jdbc.sql.BytesQuery;
10-
import org.cactoos.Text;
11-
import org.cactoos.text.HexOf;
12-
import org.cactoos.text.Sticky;
13-
import org.cactoos.text.UncheckedText;
1410

1511
/**
1612
* CacheKey.
1713
* @since 0.9.0
1814
*/
19-
public final class CacheKey implements Key<Query> {
20-
/**
21-
* Query.
22-
*/
23-
private final Query qry;
24-
25-
/**
26-
* Hash.
27-
*/
28-
private final UncheckedText hsh;
29-
15+
public final class CacheKey extends KeyEnvelope<Query> {
3016
/**
3117
* Ctor.
32-
* @param query The query
18+
* @param query A query
3319
*/
3420
public CacheKey(final Query query) {
35-
this(
36-
query,
37-
new Sticky(new HexOf(new Murmur3Hash(new BytesQuery(query))))
38-
);
39-
}
40-
41-
/**
42-
* Ctor.
43-
* @param query The query
44-
* @param hash The query's hash
45-
*/
46-
public CacheKey(final Query query, final Text hash) {
47-
this(query, new UncheckedText(hash));
48-
}
49-
50-
/**
51-
* Ctor.
52-
* @param query The query
53-
* @param hash The query's hash
54-
*/
55-
public CacheKey(final Query query, final UncheckedText hash) {
56-
this.qry = query;
57-
this.hsh = hash;
58-
}
59-
60-
@Override
61-
public Query domain() {
62-
return this.qry;
63-
}
64-
65-
@Override
66-
public String hash() {
67-
return this.hsh.asString();
68-
}
69-
70-
@Override
71-
public boolean equals(final Object other) {
72-
return other instanceof CacheKey
73-
&& this.hash().equals(CacheKey.class.cast(other).hash());
74-
}
75-
76-
@Override
77-
public int hashCode() {
78-
return this.hash().hashCode();
21+
super(query, new BytesQuery(query));
7922
}
8023
}

src/main/java/com/github/fabriciofx/cactoos/jdbc/cache/Entry.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/main/java/com/github/fabriciofx/cactoos/jdbc/cache/Instrumented.java

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/main/java/com/github/fabriciofx/cactoos/jdbc/cache/Key.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)