com.rustknife.jknife.cache.DefaultRedisCachePrefix Maven / Gradle / Ivy
The newest version!
package com.rustknife.jknife.cache;
import org.springframework.data.redis.cache.CacheKeyPrefix;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Default implementation for {@link CacheKeyPrefix} which uses the given cache name and a delimiter for creating the
* prefix.
*
* @author yoke
*/
public class DefaultRedisCachePrefix implements CacheKeyPrefix
{
private final RedisSerializer serializer = new StringRedisSerializer();
private final String delimiter;
public DefaultRedisCachePrefix() {
this(":");
}
public DefaultRedisCachePrefix(String delimiter) {
this.delimiter = delimiter;
}
public byte[] prefix(String cacheName) {
return serializer.serialize((delimiter != null ? cacheName.concat(delimiter) : cacheName.concat(":")));
}
@Override
public String compute(String cacheName) {
return delimiter != null ? cacheName.concat(delimiter) : cacheName.concat(":");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy