Skip to content

Commit 85c07d5

Browse files
authored
Merge pull request #427 from aol/cache-cleanup
Cache cleanup
2 parents 310c178 + 8313d3f commit 85c07d5

File tree

15 files changed

+182
-156
lines changed

15 files changed

+182
-156
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=1.2.3
1+
version=1.2.4
22
springVersion=5.1.8.RELEASE
33
springBootVersion=2.1.6.RELEASE
44
jerseyVersion=2.28

micro-elasticache/src/main/java/com/oath/micro/server/elasticache/ConfigureElasticache.java

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

micro-elasticache/src/main/java/com/oath/micro/server/elasticache/DistributedCacheManager.java

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

micro-elasticache/src/main/resources/META-INF/services/com.oath.micro.server.Plugin

Lines changed: 0 additions & 1 deletion
This file was deleted.

micro-elasticache/src/test/java/com/oath/micros/server/elasticache/TransientElasticacheDataConnectionTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Elasticache plugin for BASE microservices
22

3-
[micro-elasticache example apps](https://github.com/aol/micro-server/tree/master/micro-elasticache/src/test/java/app)
3+
[micro-memcached example apps](https://github.com/aol/micro-server/tree/master/micro-memcached/src/test/java/app)
44

55
Basically Available Soft statE
66

@@ -24,11 +24,11 @@ elasticache.max.retries is the maximum number of retries before client throws er
2424
```xml
2525
<dependency>
2626
<groupId>com.oath.microservices</groupId>
27-
<artifactId>micro-elasticache</artifactId>
27+
<artifactId>micro-memcached</artifactId>
2828
<version>x.yz</version>
2929
</dependency>
3030
```
3131
### Gradle
3232
```groovy
33-
compile 'com.oath.microservices:micro-elasticache:x.yz'
33+
compile 'com.oath.microservices:micro-memcached:x.yz'
3434
```
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
description = 'micro-elasticache'
1+
description = 'micro-memcached'
22

33
apply plugin: 'groovy'
44
apply plugin: 'java'
@@ -42,7 +42,7 @@ modifyPom {
4242
inceptionYear '2015'
4343

4444
groupId 'com.oath.microservices'
45-
artifactId 'micro-elasticache'
45+
artifactId 'micro-memcached'
4646
version "$version"
4747

4848

@@ -71,6 +71,11 @@ modifyPom {
7171
name 'Gordon Morrow'
7272
email 'gordon.morrow@teamaol.com'
7373
}
74+
developer {
75+
id 'davidartplus'
76+
name 'David Guzman'
77+
email 'davidartplus@gmail.com'
78+
}
7479
}
7580

7681
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.oath.micro.server.memcached;
2+
import java.util.Optional;
3+
4+
public interface DistributedCache<K, V> {
5+
void setConnectionTested(boolean result);
6+
boolean isAvailable();
7+
boolean add(K key, int exp, V value);
8+
Optional<V> get(K key);
9+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.oath.micro.server.memcached;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import net.spy.memcached.MemcachedClient;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
8+
import java.io.IOException;
9+
import java.net.InetSocketAddress;
10+
11+
@Component
12+
@Slf4j
13+
public class DistributedCacheFactory {
14+
15+
private final ElasticacheConfig config;
16+
17+
@Autowired
18+
public DistributedCacheFactory(ElasticacheConfig config) {
19+
this.config = config;
20+
}
21+
22+
public <K, V> DistributedCache<K, V> create() {
23+
try {
24+
log.info("Creating Memcached Data connection for elasticache cluster: {}", config.getHostname());
25+
return new MemcachedCacheImpl(createMemcachedClient(), config.getRetryAfterSecs(), config.getMaxRetries());
26+
}
27+
catch (Exception e) {
28+
log.error("Failed to create transient data connection", e);
29+
return null;
30+
}
31+
}
32+
33+
private MemcachedClient createMemcachedClient() {
34+
try {
35+
log.info("Starting an instance of memcache client towards elasticache cluster");
36+
return new MemcachedClient(new InetSocketAddress(config.getHostname(), config.getPort()));
37+
} catch (IOException e) {
38+
log.error("Could not initialize connection to elasticache cluster", e);
39+
return null;
40+
}
41+
42+
}
43+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.oath.micro.server.memcached;
2+
3+
4+
5+
import lombok.Getter;
6+
import lombok.extern.slf4j.Slf4j;
7+
8+
import java.io.IOException;
9+
10+
11+
import net.spy.memcached.MemcachedClient;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
16+
17+
import java.net.InetSocketAddress;
18+
19+
@Slf4j
20+
@Getter
21+
@Configuration
22+
public class ElasticacheConfig {
23+
private final String hostname;
24+
private final int port;
25+
private final int retryAfterSecs;
26+
private final int maxRetries;
27+
28+
@Autowired
29+
public ElasticacheConfig(@Value("${elasticache.hostname:null}") String hostname,
30+
@Value("${elasticache.port:6379}") int port,
31+
@Value("${elasticache.retry.after.seconds:1}") int retryAfterSecs,
32+
@Value("${elasticache.max.retries:3}") int maxRetries) {
33+
this.hostname = hostname;
34+
this.port = port;
35+
this.retryAfterSecs = retryAfterSecs;
36+
this.maxRetries = maxRetries;
37+
}
38+
}
39+

0 commit comments

Comments
 (0)