66import lombok .EqualsAndHashCode ;
77import lombok .Getter ;
88import lombok .extern .slf4j .Slf4j ;
9- import net .spy .memcached .CASValue ;
10- import net .spy .memcached .MemcachedClient ;
119
1210import java .util .Collection ;
1311import java .util .HashMap ;
@@ -53,7 +51,7 @@ public class Bucket {
5351 * If null, this means the key is uncacheable (possibly because the cache is down).
5452 * If not null, the IV holds the Entity or NEGATIVE.
5553 */
56- private final CASValue < Object > casValue ;
54+ private final IdentifiableValue identifiableValue ;
5755
5856 /**
5957 * The Entity to store in this bucket in a put(). Can be null to indicate a negative cache
@@ -70,21 +68,21 @@ public Bucket(final Key key)
7068 }
7169
7270 /**
73- * @param casValue can be null to indicate an uncacheable key
71+ * @param identifiableValue can be null to indicate an uncacheable key
7472 */
75- public Bucket (final Key key , final CASValue < Object > casValue ) {
73+ public Bucket (final Key key , final IdentifiableValue identifiableValue ) {
7674 this .key = key ;
77- this .casValue = casValue ;
75+ this .identifiableValue = identifiableValue ;
7876 }
7977
8078 /** */
8179 public Key getKey () { return this .key ; }
8280
8381 /** @return true if we can cache this bucket; false if the key isn't cacheable or the memcache was down when we created the bucket */
84- public boolean isCacheable () { return this .casValue != null ; }
82+ public boolean isCacheable () { return this .identifiableValue != null ; }
8583
8684 /** @return true if this is a negative cache result */
87- public boolean isNegative () { return this .isCacheable () && NEGATIVE .equals (casValue .getValue ()); }
85+ public boolean isNegative () { return this .isCacheable () && NEGATIVE .equals (identifiableValue .getValue ()); }
8886
8987 /**
9088 * "Empty" means we don't know the value - it could be null, it could be uncacheable, or we could have some
@@ -94,13 +92,13 @@ public Bucket(final Key key, final CASValue<Object> casValue) {
9492 * @return true if this is empty or uncacheable or something other than a nice entity or negative result.
9593 */
9694 public boolean isEmpty () {
97- return !this .isCacheable () || (!this .isNegative () && !(casValue .getValue () instanceof Entity ));
95+ return !this .isCacheable () || (!this .isNegative () && !(identifiableValue .getValue () instanceof Entity ));
9896 }
9997
10098 /** Get the entity stored at this bucket, possibly the one that was set */
10199 public Entity getEntity () {
102- if (casValue != null && casValue .getValue () instanceof Entity )
103- return (Entity )casValue .getValue ();
100+ if (identifiableValue != null && identifiableValue .getValue () instanceof Entity )
101+ return (Entity )identifiableValue .getValue ();
104102 else
105103 return null ;
106104 }
@@ -142,31 +140,29 @@ private Object getNextToStore() {
142140 /**
143141 * Creates a memcache which caches everything without expiry and doesn't record statistics.
144142 */
145- public EntityMemcache (final MemcachedClient memcache , final String namespace ) {
143+ public EntityMemcache (final MemcacheService memcache , final String namespace ) {
146144 this (memcache , namespace , key -> 0 );
147145 }
148146
149147 /**
150148 * Creates a memcache which doesn't record stats
151149 */
152- public EntityMemcache (final MemcachedClient memcache , final String namespace , final CacheControl cacheControl ) {
150+ public EntityMemcache (final MemcacheService memcache , final String namespace , final CacheControl cacheControl ) {
153151 this (memcache , namespace , cacheControl , new MemcacheStats () {
154152 @ Override public void recordHit (Key key ) { }
155153 @ Override public void recordMiss (Key key ) { }
156154 });
157155 }
158156
159157 public EntityMemcache (
160- final MemcachedClient memcachedClient ,
158+ final MemcacheService memcacheService ,
161159 final String namespace ,
162160 final CacheControl cacheControl ,
163161 final MemcacheStats stats ) {
164162
165- final MemcacheServiceImpl service = new MemcacheServiceImpl (memcachedClient );
166-
167163 this .namespace = namespace ;
168- this .memcache = new KeyMemcacheService (service );
169- this .memcacheWithRetry = new KeyMemcacheService (MemcacheServiceRetryProxy .createProxy (service ));
164+ this .memcache = new KeyMemcacheService (memcacheService );
165+ this .memcacheWithRetry = new KeyMemcacheService (MemcacheServiceRetryProxy .createProxy (memcacheService ));
170166 this .stats = stats ;
171167 this .cacheControl = cacheControl ;
172168 }
@@ -198,7 +194,7 @@ public Map<Key, Bucket> getAll(final Iterable<Key> keys) {
198194 potentials .add (key );
199195 }
200196
201- Map <Key , CASValue < Object > > casValues ;
197+ Map <Key , IdentifiableValue > casValues ;
202198 try {
203199 casValues = this .memcache .getIdentifiables (potentials );
204200 } catch (Exception ex ) {
@@ -210,7 +206,7 @@ public Map<Key, Bucket> getAll(final Iterable<Key> keys) {
210206
211207 // Now create the remaining buckets
212208 for (final Key key : keys ) {
213- final CASValue < Object > casValue = casValues .get (key ); // Might be null, which means uncacheable
209+ final IdentifiableValue casValue = casValues .get (key ); // Might be null, which means uncacheable
214210 final Bucket buck = new Bucket (key , casValue );
215211 result .put (key , buck );
216212
@@ -291,7 +287,7 @@ private Set<Key> cachePutIfUntouched(final Iterable<Bucket> buckets) {
291287 continue ;
292288 }
293289
294- payload .put (buck .getKey (), new CasPut (buck .casValue , buck .getNextToStore (), expirySeconds ));
290+ payload .put (buck .getKey (), new CasPut (buck .identifiableValue , buck .getNextToStore (), expirySeconds ));
295291 }
296292
297293 successes .addAll (this .memcache .putIfUntouched (payload ));
0 commit comments