Search in sources :

Example 6 with CacheKey

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();
}
Also used : Element(net.sf.ehcache.Element) CacheKey(org.apereo.portal.utils.cache.CacheKey)

Example 7 with CacheKey

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;
}
Also used : Element(net.sf.ehcache.Element) CacheKey(org.apereo.portal.utils.cache.CacheKey)

Example 8 with CacheKey

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);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) PipelineEventReaderImpl(org.apereo.portal.rendering.PipelineEventReaderImpl) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Example 9 with CacheKey

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);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Element(net.sf.ehcache.Element) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Example 10 with CacheKey

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);
}
Also used : StAXPipelineComponent(org.apereo.portal.rendering.StAXPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) PipelineEventReaderImpl(org.apereo.portal.rendering.PipelineEventReaderImpl) XMLEventBufferReader(org.apereo.portal.xml.stream.XMLEventBufferReader) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Aggregations

CacheKey (org.apereo.portal.utils.cache.CacheKey)23 Element (net.sf.ehcache.Element)9 Test (org.junit.Test)6 Ehcache (net.sf.ehcache.Ehcache)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 OpenEntityManager (org.apereo.portal.jpa.OpenEntityManager)3 PipelineEventReaderImpl (org.apereo.portal.rendering.PipelineEventReaderImpl)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 Deque (java.util.Deque)2 XMLEventReader (javax.xml.stream.XMLEventReader)2 XMLEvent (javax.xml.stream.events.XMLEvent)2 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)2 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)2 CharacterPipelineComponent (org.apereo.portal.rendering.CharacterPipelineComponent)2 StAXPipelineComponent (org.apereo.portal.rendering.StAXPipelineComponent)2 SimpleCacheEntryTag (org.apereo.portal.utils.cache.SimpleCacheEntryTag)2 Serializable (java.io.Serializable)1 LinkedHashMap (java.util.LinkedHashMap)1