@RequestMapping("{cacheName}/{key}/details") @ResponseBody public Object keyDetail( @PathVariable("cacheName") String cacheName, @PathVariable("key") String key, Model model) { Element element = cacheManager.getCache(cacheName).get(key); String dataPattern = "yyyy-MM-dd hh:mm:ss"; Map<String, Object> data = Maps.newHashMap(); data.put("objectValue", element.getObjectValue().toString()); data.put("size", PrettyMemoryUtils.prettyByteSize(element.getSerializedSize())); data.put("hitCount", element.getHitCount()); Date latestOfCreationAndUpdateTime = new Date(element.getLatestOfCreationAndUpdateTime()); data.put( "latestOfCreationAndUpdateTime", DateFormatUtils.format(latestOfCreationAndUpdateTime, dataPattern)); Date lastAccessTime = new Date(element.getLastAccessTime()); data.put("lastAccessTime", DateFormatUtils.format(lastAccessTime, dataPattern)); if (element.getExpirationTime() == Long.MAX_VALUE) { data.put("expirationTime", "不过期"); } else { Date expirationTime = new Date(element.getExpirationTime()); data.put("expirationTime", DateFormatUtils.format(expirationTime, dataPattern)); } data.put("timeToIdle", element.getTimeToIdle()); data.put("timeToLive", element.getTimeToLive()); data.put("version", element.getVersion()); return data; }
/** * Create a new write operation for a particular element and creation time * * @param element the element to write * @param creationTime the creation time of the operation */ public WriteOperation(Element element, long creationTime) { this.element = new Element( element.getObjectKey(), element.getObjectValue(), element.getVersion(), element.getCreationTime(), element.getLastAccessTime(), element.getHitCount(), false, element.getTimeToLive(), element.getTimeToIdle(), element.getLastUpdateTime()); this.creationTime = creationTime; }