use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class AnyUnblockedGrantPermissionPolicy method hasUnblockedPathToGrantWithCache.
private boolean hasUnblockedPathToGrantWithCache(IAuthorizationService service, IAuthorizationPrincipal principal, IPermissionOwner owner, IPermissionActivity activity, IPermissionTarget target, Set<IGroupMember> seenGroups) throws GroupsException {
final CacheKey cacheKey = getCacheKey(principal, owner, activity, target);
Element element = hasUnblockedGrantCache.get(cacheKey);
if (element == null) {
final boolean answer = hasUnblockedPathToGrant(service, principal, owner, activity, target, seenGroups);
element = new Element(cacheKey, answer);
hasUnblockedGrantCache.put(element);
}
return (Boolean) element.getObjectValue();
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class LayoutCachingService method getCachedLayout.
@Override
public DistributedUserLayout getCachedLayout(IPerson owner, IUserProfile profile) {
final CacheKey cacheKey = this.getCacheKey(owner, profile);
final Element element = this.layoutCache.get(cacheKey);
if (element != null) {
return (DistributedUserLayout) element.getObjectValue();
}
return null;
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class CachingCharacterPipelineComponentTest method testCacheMiss.
@Test
public void testCacheMiss() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final List<CharacterEvent> eventBuffer = Collections.emptyList();
final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(new CharacterEventBufferReader(eventBuffer.listIterator()));
final Ehcache cache = createMock(Ehcache.class);
final CharacterPipelineComponent targetComponent = createMock(CharacterPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(null);
expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
cache.put((Element) notNull());
expectLastCall();
replay(cache, targetComponent, elementsProvider);
final CachingCharacterPipelineComponent cachingComponent = new CachingCharacterPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<CharacterEventReader, CharacterEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class CachingCharacterPipelineComponentTest method testCacheHit.
@Test
public void testCacheHit() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final CachedEventReader<CharacterEvent> eventReader = new CachedEventReader<CharacterEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
final Element cacheElement = new Element(cacheKey, eventReader);
final Ehcache cache = createMock(Ehcache.class);
final CharacterPipelineComponent targetComponent = createMock(CharacterPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(cacheElement);
replay(cache, targetComponent, elementsProvider);
final CachingCharacterPipelineComponent cachingComponent = new CachingCharacterPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<CharacterEventReader, CharacterEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheMiss.
@Test
public void testCacheMiss() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final List<XMLEvent> eventBuffer = Collections.emptyList();
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(new XMLEventBufferReader(eventBuffer.listIterator()));
final Ehcache cache = createMock(Ehcache.class);
final StAXPipelineComponent targetComponent = createMock(StAXPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(null);
expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
cache.put((Element) notNull());
expectLastCall();
replay(cache, targetComponent, elementsProvider);
final CachingStAXPipelineComponent cachingComponent = new CachingStAXPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<XMLEventReader, XMLEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
Aggregations