From b4ffc61014156cf0c3f8d327cb59ee6923c9d27e Mon Sep 17 00:00:00 2001 From: wentch <22250530@qq.com> Date: Fri, 18 Dec 2015 16:40:50 +0800 Subject: [PATCH] --- .../redkale/service/CacheSourceService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/org/redkale/service/CacheSourceService.java b/src/org/redkale/service/CacheSourceService.java index 39db477d7..28b3cb252 100644 --- a/src/org/redkale/service/CacheSourceService.java +++ b/src/org/redkale/service/CacheSourceService.java @@ -98,7 +98,12 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { }, 10, 10, TimeUnit.SECONDS); logger.finest(self.getClass().getSimpleName() + ":" + self.name() + " start schedule expire executor"); } - if (this.storeKeyType == null || Sncp.isRemote(self)) return; + if (Sncp.isRemote(self)) return; + + boolean datasync = false; //是否从远程同步过数据 + //----------同步数据……----------- + // TODO + if (this.storeKeyType == null) return; try { CacheEntry.initCreator(); File store = new File(home, "cache/" + name()); @@ -109,6 +114,8 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { while ((line = reader.readLine()) != null) { if (line.isEmpty()) continue; CacheEntry entry = convert.convertFrom(storeType, line); + if (entry.isExpired()) continue; + if (datasync && container.containsKey(entry.key)) continue; //已经同步了 container.put(entry.key, entry); } reader.close(); @@ -149,15 +156,14 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { if (key == null) return false; CacheEntry entry = container.get(key); if (entry == null) return false; - return !(entry.expireSeconds > 0 && entry.lastAccessed + entry.expireSeconds < (System.currentTimeMillis() / 1000)); + return !entry.isExpired(); } @Override public T get(Serializable key) { if (key == null) return null; CacheEntry entry = container.get(key); - if (entry == null) return null; - if (entry.expireSeconds > 0 && entry.lastAccessed + entry.expireSeconds < (System.currentTimeMillis() / 1000)) return null; + if (entry == null || entry.isExpired()) return null; return (T) entry.getValue(); } @@ -329,6 +335,11 @@ public class CacheSourceService implements CacheSource, Service, AutoCloseable { return JsonFactory.root().getConvert().convertTo(this); } + @Ignore + public boolean isExpired() { + return (expireSeconds > 0 && lastAccessed + expireSeconds < (System.currentTimeMillis() / 1000)); + } + public int getExpireSeconds() { return expireSeconds; }