Commit b46d8004 authored by Matija Obreza's avatar Matija Obreza

Tiles cache

parent c8957d94
......@@ -104,4 +104,6 @@ public interface MappingService {
return (int) ((Math.floor(((180.0 + lng) / 360.0) * pixAtZoom)) - tile * 256);
}
}
void clearCache();
}
......@@ -30,7 +30,10 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.MappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -104,10 +107,16 @@ public class MappingServiceImpl implements MappingService {
}
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Override
@CacheEvict(value = "tileserver", allEntries = true)
public void clearCache() {
LOG.warn("Cleared tiles cache");
}
// TODO Add caching
@Override
// @Cacheable(value="tileserver",
// key="'tile-' + #zoom + '-' + #xtile + '-' + #ytile + '-' + #jsonFilter")
@Cacheable(value = "tileserver", key = "'tile-' + #zoom + '-' + #xtile + '-' + #ytile + '-' + #jsonFilter")
public byte[] getTile(String jsonFilter, final int zoom, final int xtile, final int ytile) {
final BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
......
......@@ -34,12 +34,15 @@ import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.LuceneIndexer;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.impl.ContentSanitizer;
import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
import org.genesys2.server.service.worker.InstituteUpdater;
import org.genesys2.server.service.worker.SGSVInsertMissing;
import org.genesys2.server.service.worker.SGSVUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -47,6 +50,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.hazelcast.core.IMap;
@Controller
@RequestMapping("/admin")
public class AdminController {
......@@ -85,6 +90,12 @@ public class AdminController {
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
private MappingService mappingService;
@Autowired
private CacheManager cacheManager;
@RequestMapping("/")
public String root(Model model) {
return "/admin/index";
......@@ -303,4 +314,22 @@ public class AdminController {
LOG.info("Updating done");
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/clearTilesCache")
public String clearTilesCache() {
Cache tileServerCache = cacheManager.getCache("tileserver");
System.err.println("tileServerCache=" + tileServerCache.getNativeCache());
IMap hazelCache = (IMap) tileServerCache.getNativeCache();
LOG.info("Tiles cache size=" + hazelCache.size());
int count = 0;
for (Object key : hazelCache.keySet()) {
LOG.info("\tkey=" + key);
if (++count > 20)
break;
}
mappingService.clearCache();
LOG.info("Tiles cache size=" + hazelCache.size());
return "redirect:/admin/";
}
}
......@@ -77,7 +77,7 @@
</hz:network>
<hz:map name="default" max-idle-seconds="3600" max-size="5000"
time-to-live-seconds="0" eviction-policy="LRU" />
<hz:map name="tileserver" max-size="1000" eviction-policy="LFU" />
<hz:map name="tileserver" max-size="${cache.tileserver.max-size}" max-idle-seconds="${cache.tileserver.max-idle-seconds}" time-to-live-seconds="${cache.tileserver.time-to-live-seconds}" eviction-policy="${cache.tileserver.eviction-policy}" />
</hz:config>
</hz:hazelcast>
......@@ -106,7 +106,7 @@
</hz:network>
<hz:map name="default" max-idle-seconds="300" max-size="1000"
time-to-live-seconds="0" eviction-policy="LRU" />
<hz:map name="tileserver" max-size="1000" eviction-policy="LFU" />
<hz:map name="tileserver" max-size="${cache.tileserver.max-size}" max-idle-seconds="${cache.tileserver.max-idle-seconds}" time-to-live-seconds="${cache.tileserver.time-to-live-seconds}" eviction-policy="${cache.tileserver.eviction-policy}" />
</hz:config>
</hz:hazelcast>
......@@ -133,7 +133,7 @@
</hz:network>
<hz:map name="default" max-idle-seconds="300" max-size="1000"
time-to-live-seconds="0" eviction-policy="LRU" />
<hz:map name="tileserver" max-size="1000" eviction-policy="LFU" />
<hz:map name="tileserver" max-size="${cache.tileserver.max-size}" max-idle-seconds="${cache.tileserver.max-idle-seconds}" time-to-live-seconds="${cache.tileserver.time-to-live-seconds}" eviction-policy="${cache.tileserver.eviction-policy}" />
</hz:config>
</hz:hazelcast>
......
......@@ -105,3 +105,9 @@ hazelcast.aws.security-group=sg-hazelcast
theme.defaultThemeName=dev
scheduler.tokens.cleanup.hours=1
# TileServer Cache
cache.tileserver.max-size=1000
cache.tileserver.time-to-live-seconds=300
cache.tileserver.max-idle-seconds=0
cache.tileserver.eviction-policy=LRU
......@@ -12,6 +12,13 @@
<spring:message code="admin.page.title" />
</h1>
<h3>Full-text Search</h3>
<form method="post" action="<c:url value="/admin/clearTilesCache" />">
<input type="submit" class="btn btn-default" value="Clear Tiles cache" />
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<h3>Country data</h3>
<form method="post" action="<c:url value="/admin/refreshCountries" />">
<input type="submit" class="btn btn-default" value="Refresh country data" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment