argos/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialCacheServ...

68 lines
1.8 KiB
Java

package eu.eudat.service.supportivematerial;
import gr.cite.tools.cache.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Locale;
@Service
public class SupportiveMaterialCacheService extends CacheService<SupportiveMaterialCacheService.SupportiveMaterialCacheValue> {
public static class SupportiveMaterialCacheValue {
public SupportiveMaterialCacheValue() {}
public SupportiveMaterialCacheValue(String name, byte[] content) {
this.name = name;
this.content = content;
}
private String name;
private byte[] content;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
@Autowired
public SupportiveMaterialCacheService(SupportiveMaterialCacheOptions options) {
super(options);
}
@Override
protected Class<SupportiveMaterialCacheValue> valueClass() {return SupportiveMaterialCacheValue.class;}
public String keyOf(SupportiveMaterialCacheValue value) {
return this.buildKey(value.getName());
}
public String buildKey(String name) {
HashMap<String, String> keyParts = new HashMap<>();
keyParts.put("$material$", name.toLowerCase(Locale.ROOT));
//keyParts.put("$material_content$", new String(content, StandardCharsets.UTF_8).toLowerCase(Locale.ROOT));
return this.generateKey(keyParts);
}
}