Skip to content

Commit

Permalink
#461 support flexible expiration for Infinispan
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Buhtoyarov committed Apr 29, 2024
1 parent 2444e89 commit 7ac22c3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -77,12 +77,12 @@ Its key advantage lies in the configuration via properties or yaml files, elimin
### Supported JCache compatible(or similar) back-ends
In addition to local in-memory buckets, the Bucket4j supports clustered usage scenario on top of following back-ends:

| Back-end | Async supported | Flexible per-entry expiration | Optimized serialization | Thin-client support | Documentation link |
| Back-end | Async supported | Flexible per-entry expiration | Optimized serialization | Thin-client support | Documentation link |
| :--- | :---: |:-----------------------------:|:-----------------------:|:-------------------:|:-------------------------------------------------------------------------------------:|
| ```JCache API (JSR 107)``` | No | No | No | No | [bucket4j-jcache](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-jcache) |
| ```Hazelcast``` | Yes | Yes | Yes | No | [bucket4j-hazelcast](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-hazelcast) |
| ```Apache Ignite``` | Yes | No | n/a | Yes | [bucket4j-ignite](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-ignite) |
| ```Inifinispan``` | Yes | TODO | Yes | No | [bucket4j-infinispan](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-infinispan) |
| ```Inifinispan``` | Yes | Yes | Yes | No | [bucket4j-infinispan](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-infinispan) |
| ```Oracle Coherence``` | Yes | Yes | Yes | No | [bucket4j-coherence](https://bucket4j.github.io/8.12.0/toc.html#bucket4j-coherence) |

### Redis back-ends
Expand Down
Expand Up @@ -57,6 +57,11 @@ public InfinispanProxyManager<K> build() {
return new InfinispanProxyManager<>(this);
}

@Override
public boolean isExpireAfterWriteSupported() {
return true;
}

}

}
Expand Up @@ -21,12 +21,14 @@

import java.io.Serial;

import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy;
import io.github.bucket4j.distributed.remote.AbstractBinaryTransaction;
import io.github.bucket4j.distributed.remote.RemoteBucketState;
import io.github.bucket4j.distributed.remote.Request;
import io.github.bucket4j.distributed.serialization.InternalSerializationHelper;
import io.github.bucket4j.util.ComparableByContent;
import org.infinispan.functional.EntryView;
import org.infinispan.functional.MetaParam;
import org.infinispan.util.function.SerializableFunction;

public class InfinispanProcessor<K, R> implements
Expand Down Expand Up @@ -69,7 +71,13 @@ protected byte[] getRawState() {

@Override
protected void setRawState(byte[] newStateBytes, RemoteBucketState newState) {
entry.set(newStateBytes);
ExpirationAfterWriteStrategy expirationStrategy = getExpirationStrategy();
long ttlMillis = expirationStrategy == null ? -1 : expirationStrategy.calculateTimeToLiveMillis(newState, getCurrentTimeNanos());
if (ttlMillis > 0) {
entry.set(newStateBytes, new MetaParam.MetaLifespan(ttlMillis));
} else {
entry.set(newStateBytes);
}
}
}.execute();
}
Expand Down
Expand Up @@ -127,4 +127,9 @@ public <T> CompletableFuture<CommandResult<T>> executeAsync(K key, Request<T> re
}
}

@Override
public boolean isExpireAfterWriteSupported() {
return true;
}

}
Expand Up @@ -61,7 +61,7 @@ public static void init() throws MalformedURLException, URISyntaxException {
"InfinispanProxyManager",
() -> UUID.randomUUID().toString(),
() -> Bucket4jInfinispan.entryProcessorBasedBuilder(readWriteMap)
)
).checkExpiration()
);
}

Expand Down

0 comments on commit 7ac22c3

Please sign in to comment.