[java-shib-attribute] 04/05: JSATTR-29 Data connector caching improvements
Scott Cantor
cantor.2 at osu.edu
Thu Jul 25 17:41:41 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch maint-5.1
in repository java-shib-attribute.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=5eaf3c1b51dd29ef9c9f00f584db0b5747a11e66
commit 5eaf3c1b51dd29ef9c9f00f584db0b5747a11e66
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 11 15:48:18 2024 +0100
JSATTR-29 Data connector caching improvements
https://shibboleth.atlassian.net/browse/JSATTR-29
Add test to prove that we do do negative caching. Clean up logging in the negative cache hit case
---
.../resolver/dc/impl/AbstractSearchDataConnector.java | 9 +++++++--
.../resolver/dc/rdbms/impl/RDBMSDataConnectorTest.java | 18 ++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/impl/AbstractSearchDataConnector.java b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/impl/AbstractSearchDataConnector.java
index feef21b1d..641c794fd 100644
--- a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/impl/AbstractSearchDataConnector.java
+++ b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/impl/AbstractSearchDataConnector.java
@@ -181,13 +181,18 @@ public abstract class AbstractSearchDataConnector<T1 extends ExecutableSearch,T2
final String cacheKey = executable.getResultCacheKey();
if (cacheKey != null) {
resolvedAttributes = cache.getIfPresent(cacheKey);
- log.debug("{} Cache key returned, resolved attributes {} using cache {}", new Object[] {getLogPrefix(),
- resolvedAttributes, resultsCache,});
+
if (resolvedAttributes == null) {
+ log.debug("{} Cache key did not found anything in cache {}", new Object[] {getLogPrefix(), resultsCache,});
resolvedAttributes = retrieveAttributes(executable);
log.debug("{} Resolved attributes {}", getLogPrefix(), resolvedAttributes);
cache.put(cacheKey, resolvedAttributes != null ? resolvedAttributes
: CollectionSupport.<String,IdPAttribute>emptyMap());
+ } else if (resolvedAttributes.isEmpty()){
+ log.debug("{} Cache key found empty (negative) result using cache {}", new Object[] {getLogPrefix(), resultsCache,});
+ } else {
+ log.debug("{} Cache key returned resolved attributes {} using cache {}", new Object[] {getLogPrefix(),
+ resolvedAttributes, resultsCache,});
}
} else {
log.debug("No cache key returned, will not check for cached results");
diff --git a/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/rdbms/impl/RDBMSDataConnectorTest.java b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/rdbms/impl/RDBMSDataConnectorTest.java
index 7c4a288b0..d9aad545f 100644
--- a/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/rdbms/impl/RDBMSDataConnectorTest.java
+++ b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/rdbms/impl/RDBMSDataConnectorTest.java
@@ -325,6 +325,24 @@ public class RDBMSDataConnectorTest {
assertEquals(cache.iterator().next(), optional);
}
+ @Test public void testNegativeCache() throws ComponentInitializationException, ResolutionException {
+ final RDBMSDataConnector connector = createUserRdbmsDataConnector(null, null);
+ final TestCache cache = new TestCache();
+ connector.setResultsCache(cache);
+ connector.initialize();
+
+ final AttributeResolutionContext context =
+ TestSources.createResolutionContext("I_DONT_EXIST", TestSources.IDP_ENTITY_ID,
+ TestSources.SP_ENTITY_ID);
+ assertTrue(cache.size() == 0);
+ Map<String, IdPAttribute> optional = connector.resolve(context);
+ assertNull(optional);
+ assertTrue(cache.size() == 1);
+ optional = connector.resolve(context);
+ assertTrue(optional == null || optional.isEmpty());
+ assertTrue(cache.size() == 1);
+ }
+
@Test public void resolveMultiple() throws ComponentInitializationException, ResolutionException {
final RDBMSDataConnector connector = createGroupRdbmsDataConnector(null, null);
connector.initialize();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list