Commit 233a21a8 authored by Matija Obreza's avatar Matija Obreza
Browse files

Clear cache by name

parent d0f09b86
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.admin;
import java.util.ArrayList;
......@@ -15,6 +31,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.DistributedObject;
import com.hazelcast.core.Hazelcast;
......@@ -22,6 +39,11 @@ import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.monitor.LocalMapStats;
/**
* Manage caches
*
* @author mobreza
*/
@Controller
@RequestMapping("/admin/cache")
@PreAuthorize("hasRole('ADMINISTRATOR')")
......@@ -35,7 +57,6 @@ public class CacheController {
@Autowired
private CacheManager cacheManager;
@RequestMapping(method = RequestMethod.POST, value = "/clearTilesCache")
public String clearTilesCache() {
final Cache tileServerCache = cacheManager.getCache("tileserver");
......@@ -61,14 +82,23 @@ public class CacheController {
@RequestMapping(method = RequestMethod.POST, value = "/clearCaches")
public String clearCaches() {
for (String cacheName : cacheManager.getCacheNames()) {
clearCache(cacheName);
}
return "redirect:/admin/cache/";
}
@RequestMapping(method = RequestMethod.POST, value = "/clearCache")
public String clearCache(@RequestParam(required = true, value = "name") String cacheName) {
final Cache cache = cacheManager.getCache(cacheName);
if (cache != null) {
LOG.info("Clearing cache " + cacheName);
cache.clear();
} else {
LOG.info("No such cache: " + cacheName);
}
return "redirect:/admin/cache/";
}
@RequestMapping("/")
public String cacheStats(Model model) {
List<CacheStats> cacheMaps = new ArrayList<CacheStats>();
......
......@@ -32,6 +32,12 @@
<c:out value="${cacheMap.serviceName}" />
<c:out value="${cacheMap.name}" />
</h3>
<form method="post" action="<c:url value="/admin/cache/clearCache" />">
<input type="hidden" name="name" value="${cacheMap.name}" />
<input type="submit" class="btn btn-default" value="Clear" />
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
<c:set value="${cacheMap.mapStats}" var="mapStat" />
<div class="row">
......
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