11package com .jarvis .cache .map ;
22
33import com .jarvis .cache .ICacheManager ;
4+ import com .jarvis .cache .MSetParam ;
45import com .jarvis .cache .clone .ICloner ;
56import com .jarvis .cache .exception .CacheCenterConnectionException ;
67import com .jarvis .cache .to .AutoLoadConfig ;
1112
1213import java .lang .ref .SoftReference ;
1314import java .lang .reflect .Method ;
15+ import java .util .HashMap ;
16+ import java .util .Map ;
1417import java .util .Set ;
1518import java .util .concurrent .ConcurrentHashMap ;
1619
@@ -70,7 +73,7 @@ public MapCacheManager(AutoLoadConfig config, ICloner cloner) {
7073 }
7174
7275 public MapCacheManager (AutoLoadConfig config , ICloner cloner , int initSize ) {
73- this .cache = new ConcurrentHashMap <String , Object >(initSize );
76+ this .cache = new ConcurrentHashMap <>(initSize );
7477 this .config = config ;
7578 this .config .setCheckFromCacheBeforeLoad (false );
7679 this .cloner = cloner ;
@@ -103,7 +106,7 @@ public void setCache(final CacheKeyTO cacheKeyTO, final CacheWrapper<Object> res
103106 return ;
104107 }
105108 String cacheKey = cacheKeyTO .getCacheKey ();
106- if (null == cacheKey || cacheKey .length () == 0 ) {
109+ if (null == cacheKey || cacheKey .isEmpty () ) {
107110 return ;
108111 }
109112 CacheWrapper <Object > value = null ;
@@ -119,7 +122,7 @@ public void setCache(final CacheKeyTO cacheKeyTO, final CacheWrapper<Object> res
119122 }
120123 SoftReference <CacheWrapper <Object >> reference = new SoftReference <CacheWrapper <Object >>(value );
121124 String hfield = cacheKeyTO .getHfield ();
122- if (null == hfield || hfield .length () == 0 ) {
125+ if (null == hfield || hfield .isEmpty () ) {
123126 cache .put (cacheKey , reference );
124127 } else {
125128 Object tmpObj = cache .get (cacheKey );
@@ -145,6 +148,16 @@ public void setCache(final CacheKeyTO cacheKeyTO, final CacheWrapper<Object> res
145148 this .changeListener .cacheChange ();
146149 }
147150
151+ @ Override
152+ public void mset (final Method method , final MSetParam ... params ) throws CacheCenterConnectionException {
153+ if (null == params || params .length == 0 ) {
154+ return ;
155+ }
156+ for (MSetParam param : params ) {
157+ this .setCache (param .getCacheKey (), param .getResult (), method );
158+ }
159+ }
160+ 148161 @ SuppressWarnings ("unchecked" )
149162 @ Override
150163 public CacheWrapper <Object > get (final CacheKeyTO cacheKeyTO , final Method method )
@@ -153,7 +166,7 @@ public CacheWrapper<Object> get(final CacheKeyTO cacheKeyTO, final Method method
153166 return null ;
154167 }
155168 String cacheKey = cacheKeyTO .getCacheKey ();
156- if (null == cacheKey || cacheKey .length () == 0 ) {
169+ if (null == cacheKey || cacheKey .isEmpty () ) {
157170 return null ;
158171 }
159172 Object obj = cache .get (cacheKey );
@@ -162,7 +175,7 @@ public CacheWrapper<Object> get(final CacheKeyTO cacheKeyTO, final Method method
162175 }
163176 String hfield = cacheKeyTO .getHfield ();
164177 CacheWrapper <Object > value = null ;
165- if (null == hfield || hfield .length () == 0 ) {
178+ if (null == hfield || hfield .isEmpty () ) {
166179 if (obj instanceof SoftReference ) {
167180 SoftReference <CacheWrapper <Object >> reference = (SoftReference <CacheWrapper <Object >>) obj ;
168181 if (null != reference ) {
@@ -200,6 +213,19 @@ public CacheWrapper<Object> get(final CacheKeyTO cacheKeyTO, final Method method
200213 return value ;
201214 }
202215
216+ @ Override
217+ public Map <CacheKeyTO , CacheWrapper <Object >> mget (final Method method , final CacheKeyTO ... keys ) throws CacheCenterConnectionException {
218+ if (null == keys || keys .length == 0 ) {
219+ return null ;
220+ }
221+ int len = keys .length ;
222+ Map <CacheKeyTO , CacheWrapper <Object >> res = new HashMap <>(len );
223+ for (int i = 0 ; i < len ; i ++) {
224+ res .put (keys [i ], get (keys [i ], method ));
225+ }
226+ return res ;
227+ }
228+ 203229 @ SuppressWarnings ("unchecked" )
204230 @ Override
205231 public void delete (Set <CacheKeyTO > keys ) throws CacheCenterConnectionException {
0 commit comments