es.moki.ratelimitj.inmemory.request.SavedKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ratelimitj-inmemory Show documentation
Show all versions of ratelimitj-inmemory Show documentation
The RateLimitJ project aims to provide a modular rate limiting solution
package es.moki.ratelimitj.inmemory.request;
import java.util.OptionalInt;
public class SavedKey {
public final long blockId;
public final long blocks;
public final long trimBefore;
public final String countKey;
public final String tsKey;
public SavedKey(long now, int duration, OptionalInt precisionOpt) {
int precision = precisionOpt.orElse(duration);
precision = Math.min(precision, duration);
this.blocks = (long) Math.ceil(duration / (double) precision);
this.blockId = (long) Math.floor(now / (double) precision);
this.trimBefore = blockId - blocks + 1;
this.countKey = "" + duration + ':' + precision + ':';
this.tsKey = countKey + 'o';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy