Skip to content

Commit dcf35eb

Browse files
committed
review: improv logging of cache invalidation
1 parent 10cab8a commit dcf35eb

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

core/src/main/java/org/pentaho/platform/engine/security/authorization/core/caching/MemoryAuthorizationDecisionCache.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ private class SessionCacheData {
7474

7575
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
7676

77+
@NonNull
78+
private final String sessionKey;
79+
7780
/**
7881
* Stores the set of sessions associated with this session cache data.
7982
* <p>
@@ -91,8 +94,10 @@ private class SessionCacheData {
9194
@NonNull
9295
private final Cache<IAuthorizationDecisionCacheKey, IAuthorizationDecision> cache;
9396

94-
public SessionCacheData( @NonNull Cache<IAuthorizationDecisionCacheKey, IAuthorizationDecision> cache,
97+
public SessionCacheData( @NonNull String sessionKey,
98+
@NonNull Cache<IAuthorizationDecisionCacheKey, IAuthorizationDecision> cache,
9599
@NonNull IPentahoSession session ) {
100+
this.sessionKey = sessionKey;
96101
this.cache = cache;
97102

98103
addSessionCore( session );
@@ -174,6 +179,13 @@ public boolean isStale() {
174179
}
175180

176181
public void invalidate( @NonNull IAuthorizationDecisionCacheKey key ) {
182+
if ( logger.isTraceEnabled() ) {
183+
logger.trace(
184+
String.format(
185+
"Invalidating cache entry for key '%s' in session cache for '%s'",
186+
key, sessionKey ) );
187+
}
188+
177189
cache.invalidate( key );
178190
}
179191

@@ -195,6 +207,17 @@ public void invalidateAll( @NonNull Predicate<IAuthorizationDecisionCacheKey> pr
195207
.filter( predicate )
196208
.toList();
197209

210+
if ( logger.isTraceEnabled() ) {
211+
for ( var key : invalidateRequests ) {
212+
logger.trace(
213+
String.format(
214+
"Invalidating cache entry for key '%s' in session cache for '%s'",
215+
key, sessionKey ) );
216+
}
217+
218+
logger.trace( String.format( "Session cache disposed for '%s'", sessionKey ) );
219+
}
220+
198221
cache.invalidateAll( invalidateRequests );
199222
}
200223

@@ -210,6 +233,10 @@ public void dispose() {
210233
} finally {
211234
lock.writeLock().unlock();
212235
}
236+
237+
if ( logger.isTraceEnabled() ) {
238+
logger.trace( String.format( "Session cache disposed for '%s'", sessionKey ) );
239+
}
213240
}
214241
}
215242

@@ -513,7 +540,7 @@ protected Cache<IAuthorizationDecisionCacheKey, IAuthorizationDecision> getSessi
513540
}
514541

515542
var cache = createSessionCache();
516-
cacheData = new SessionCacheData( cache, session );
543+
cacheData = new SessionCacheData( sessionKey, cache, session );
517544
cacheBySessionKey.put( sessionKey, cacheData );
518545
return cache;
519546
} finally {

0 commit comments

Comments
 (0)