Skip to content

Commit 5f6fa98

Browse files
docs(caching): added docs on migrating from guava cache to caffeine
Signed-off-by: Matheus Veríssimo <[email protected]>
1 parent 23cf929 commit 5f6fa98

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

providers/go-feature-flag/README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,62 @@ You will have a new instance ready to be used with your `open-feature` java SDK.
4747
| **`keepAliveDuration`** | `false` | keepAliveDuration is the time in millisecond we keep the connexion open. _(default: 7200000 (2 hours))_ |
4848
| **`apiKey`** | `false` | If the relay proxy is configured to authenticate the requests, you should provide an API Key to the provider. Please ask the administrator of the relay proxy to provide an API Key. (This feature is available only if you are using GO Feature Flag relay proxy v1.7.0 or above). _(default: null)_ |
4949
| **`enableCache`** | `false` | enable cache value. _(default: true)_ |
50-
| **`cacheConfig`** | `false` | If cache custom configuration is wanted, you should provide a [Caffeine](https://github.com/ben-manes/caffeine) configuration object. _(default: null)_ |
50+
| **`cacheConfig`** | `false` | If cache custom configuration is wanted, you should provide a [Caffeine](https://github.com/ben-manes/caffeine) configuration object. _(default: null)_ |
5151
| **`flushIntervalMs`** | `false` | interval time we publish statistics collection data to the proxy. The parameter is used only if the cache is enabled, otherwise the collection of the data is done directly when calling the evaluation API. _(default: 1000 ms)_ |
5252
| **`maxPendingEvents`** | `false` | max pending events aggregated before publishing for collection data to the proxy. When event is added while events collection is full, event is omitted. _(default: 10000)_ |
5353
| **`flagChangePollingIntervalMs`** | `false` | interval time we poll the proxy to check if the configuration has changed.<br/>If the cache is enabled, we will poll the relay-proxy every X milliseconds to check if the configuration has changed. _(default: 120000)_ |
5454
| **`disableDataCollection`** | `false` | set to true if you don't want to collect the usage of flags retrieved in the cache. _(default: false)_ |
55+
56+
## Breaking changes
57+
58+
### 0.4.0 - Cache Implementation Change: Guava to Caffeine
59+
60+
In this release, we have updated the cache implementation from Guava to Caffeine. This change was made because Caffeine is now the recommended caching solution by the maintainers of Guava due to its performance improvements and enhanced features.
61+
62+
Because of this, the cache configuration on `GoFeatureFlagProviderOptions` that used Guava's `CacheBuilder` is now handled by `Caffeine`.
63+
64+
#### How to migrate
65+
66+
Configuration cache with Guava used to be like this:
67+
68+
```java
69+
import com.google.common.cache.CacheBuilder;
70+
// ...
71+
CacheBuilder guavaCacheBuilder = CacheBuilder.newBuilder()
72+
.initialCapacity(100)
73+
.maximumSize(2000);
74+
75+
FeatureProvider provider = new GoFeatureFlagProvider(
76+
GoFeatureFlagProviderOptions
77+
.builder()
78+
.endpoint("https://my-gofeatureflag-instance.org")
79+
.cacheBuilder(guavaCacheBuilder)
80+
.build());
81+
82+
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
83+
84+
// ...
85+
```
86+
87+
Now with Caffeine it should be like this:
88+
89+
```java
90+
import com.github.benmanes.caffeine.cache.Caffeine;
91+
// ...
92+
Caffeine caffeineCacheConfig = Caffeine.newBuilder()
93+
.initialCapacity(100)
94+
.maximumSize(2000);
95+
96+
FeatureProvider provider = new GoFeatureFlagProvider(
97+
GoFeatureFlagProviderOptions
98+
.builder()
99+
.endpoint("https://my-gofeatureflag-instance.org")
100+
.cacheConfig(caffeineCacheConfig)
101+
.build());
102+
103+
OpenFeatureAPI.getInstance().setProviderAndWait(provider);
104+
105+
// ...
106+
```
107+
108+
For a complete list of customizations options available in Caffeine, please refer to the [Caffeine documentation](https://github.com/ben-manes/caffeine/wiki) for more details.

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/controller/CacheController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
public class CacheController {
1919
public static final long DEFAULT_CACHE_TTL_MS = 5L * 60L * 1000L;
20-
public static final int DEFAULT_CACHE_CONCURRENCY_LEVEL = 1;
2120
public static final int DEFAULT_CACHE_INITIAL_CAPACITY = 100;
2221
public static final int DEFAULT_CACHE_MAXIMUM_SIZE = 100000;
2322
private final Cache<String, ProviderEvaluation<?>> cache;

0 commit comments

Comments
 (0)