use of net.sf.ehcache.Element in project ORCID-Source by ORCID.
the class StatisticsCacheManagerImpl method setLatestStatisticsTimeline.
@Override
public synchronized void setLatestStatisticsTimeline() {
LOG.info("Getting the latest statistics timeline map");
Map<StatisticsEnum, StatisticsTimeline> latestStatisticsTimelineMap = new HashMap<StatisticsEnum, StatisticsTimeline>();
for (StatisticsEnum type : StatisticsEnum.values()) {
StatisticsTimeline statisticsTimeline = statisticsManagerReadOnly.getStatisticsTimelineModel(type);
latestStatisticsTimelineMap.put(type, statisticsTimeline);
}
if (statisticsCache.get(CACHE_TIMELINE_KEY) == null) {
statisticsCache.put(new Element(CACHE_TIMELINE_KEY, latestStatisticsTimelineMap));
} else {
statisticsCache.replace(new Element(CACHE_TIMELINE_KEY, latestStatisticsTimelineMap));
}
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class LayoutCachingService method cacheLayout.
@Override
public void cacheLayout(IPerson owner, IUserProfile profile, DistributedUserLayout layout) {
final CacheKey cacheKey = this.getCacheKey(owner, profile);
this.layoutCache.put(new Element(cacheKey, layout));
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class CachingPipelineComponent method getEventReader.
/* (non-Javadoc)
* @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@SuppressWarnings("unchecked")
@Override
public final PipelineEventReader<R, E> getEventReader(HttpServletRequest request, HttpServletResponse response) {
if (Included.PLAIN == this.resourcesElementsProvider.getDefaultIncludedType()) {
this.logger.trace("{} - Resoure Aggregation Disabled, ignoring event cache and returning parent event reader directly", this.beanName);
return this.wrappedComponent.getEventReader(request, response);
}
//Get the key for this request from the target component and see if there is a cache entry
final CacheKey cacheKey = this.wrappedComponent.getCacheKey(request, response);
Element element = this.cache.get(cacheKey);
CachedEventReader<E> cachedEventReader = null;
if (element != null) {
cachedEventReader = (CachedEventReader<E>) element.getObjectValue();
}
//If there was a cached reader return it immediately
if (cachedEventReader == null) {
//No cached data for key, call target component to get events and an updated cache key
logger.debug("{} - No cached events found for key {}, calling parent", this.beanName, cacheKey);
final PipelineEventReader<R, E> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
//Copy the events from the reader into a buffer to be cached
final List<E> eventCache = new LinkedList<E>();
for (final E event : pipelineEventReader) {
//TODO add de-duplication logic here
eventCache.add(event);
}
final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
cachedEventReader = new CachedEventReader<E>(eventCache, new LinkedHashMap<String, String>(outputProperties));
//Cache the buffer
element = new Element(cacheKey, cachedEventReader);
this.cache.put(element);
logger.debug("{} - Cached {} events for key {}", this.beanName, eventCache.size(), cacheKey);
} else {
logger.debug("{} - Found cached events for key {}", this.beanName, cacheKey);
}
final List<E> eventCache = cachedEventReader.getEventCache();
final Map<String, String> outputProperties = cachedEventReader.getOutputProperties();
final R eventReader = this.createEventReader(eventCache.listIterator());
return new PipelineEventReaderImpl<R, E>(eventReader, outputProperties);
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class GroupsCacheAuthenticationListenerTest method testUserAuthenticated.
@Test
public void testUserAuthenticated() {
final IPerson person = PersonFactory.createPerson();
person.setAttribute(IPerson.USERNAME, "mock.person");
final IEntityGroup group = new MockEntityGroup("mock.group", IPerson.class);
final CacheManager cacheManager = CacheManager.getInstance();
final Cache parentGroupsCache = new Cache("parentGroupsCache", 100, false, false, 0, 0);
cacheManager.addCache(parentGroupsCache);
parentGroupsCache.put(new Element(person.getEntityIdentifier(), Collections.singleton(group)));
final Cache childrenCache = new Cache("childrenCache", 100, false, false, 0, 0);
cacheManager.addCache(childrenCache);
childrenCache.put(new Element(group.getUnderlyingEntityIdentifier(), new Object()));
Assert.assertEquals(parentGroupsCache.getSize(), 1);
Assert.assertEquals(childrenCache.getSize(), 1);
final LocalGroupsCacheAuthenticationListener listener = new LocalGroupsCacheAuthenticationListener();
listener.setParentGroupsCache(parentGroupsCache);
listener.setChildrenCache(childrenCache);
listener.userAuthenticated(person);
Assert.assertEquals(parentGroupsCache.getSize(), 0);
Assert.assertEquals(childrenCache.getSize(), 0);
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheHit.
@Test
public void testCacheHit() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final CachedEventReader<XMLEvent> eventReader = new CachedEventReader<XMLEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
final Element cacheElement = new Element(cacheKey, eventReader);
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(cacheElement);
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