Added get(key, type) method to Cache interface

This new get variant not only allows for generically specifying the required value type; it also skips the ValueWrapper that the standard get method returns. Note that it is not possible to differentiate between non-existing cache entries and cached null values that way; for that purpose, the standard get variant needs to be used.

Issue: SPR-11061
This commit is contained in:
Juergen Hoeller
2013-11-04 14:31:41 +01:00
parent b093b84954
commit 50d3f71923
9 changed files with 81 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@ public class NoOpCacheManagerTests {
Object key = new Object();
cache.put(key, new Object());
assertNull(cache.get(key));
assertNull(cache.get(key, Object.class));
assertNull(cache.getNativeCache());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,9 @@ public class ConcurrentCacheTests {
assertNull(cache.get(key));
cache.put(key, value);
assertEquals(value, cache.get(key).get());
assertEquals(value, cache.get(key, String.class));
assertEquals(value, cache.get(key, Object.class));
assertEquals(value, cache.get(key, null));
}
@Test