use of net.sf.ehcache.Element 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 net.sf.ehcache.Element in project uPortal by Jasig.
the class LrsActorService method getLrsActor.
@Override
public LrsActor getLrsActor(String userName) {
Element element = this.lrsActorCache.get(userName);
if (element != null) {
return (LrsActor) element.getObjectValue();
}
final String email;
final String name;
final IPersonAttributes person = personAttributeDao.getPerson(userName);
if (person == null) {
email = userName;
name = userName + "@example.com";
} else {
email = getEmail(person);
name = getName(person);
}
final LrsActor lrsActor = new LrsActor("mailto:" + email, name);
this.lrsActorCache.put(new Element(userName, lrsActor));
return lrsActor;
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class EntityGroupImpl method primRemoveMember.
/**
* Removes the <code>IGroupMember</code> key from the appropriate key cache, by copying the
* cache, removing the key from the copy and replacing the original with the copy. At this
* point, <code>gm</code> still has <code>this</code> in its containing groups cache. That cache
* entry is not removed until update(), when changes are committed to the store.
*
* @param gm org.apereo.portal.groups.IGroupMember
*/
private void primRemoveMember(IGroupMember gm) throws GroupsException {
final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
Element element = childrenCache.get(cacheKey);
@SuppressWarnings("unchecked") final Set<IGroupMember> set = element != null ? (Set<IGroupMember>) element.getObjectValue() : buildChildrenSet();
final Set<IGroupMember> children = new HashSet<>(set);
children.remove(gm);
childrenCache.put(new Element(cacheKey, children));
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class EntityGroupImpl method getChildren.
/**
* Returns an <code>Iterator</code> over the <code>GroupMembers</code> in our member <code>
* Collection</code>. Reflects pending changes.
*
* @return Iterator
*/
@Override
public Set<IGroupMember> getChildren() throws GroupsException {
final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
Element element = childrenCache.get(cacheKey);
if (element == null) {
final Set<IGroupMember> children = buildChildrenSet();
element = new Element(cacheKey, children);
childrenCache.put(element);
}
@SuppressWarnings("unchecked") final Set<IGroupMember> rslt = (Set<IGroupMember>) element.getObjectValue();
return rslt;
}
use of net.sf.ehcache.Element in project uPortal by Jasig.
the class GroupMemberImpl method getParentGroups.
/**
* Returns an <code>Iterator</code> over this <code>IGroupMember's</code> parent groups.
* Synchronize the collection of keys with adds and removes.
*
* @return Iterator
*/
@Override
public Set<IEntityGroup> getParentGroups() throws GroupsException {
final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
Element element = parentGroupsCache.get(cacheKey);
if (element == null) {
final Set<IEntityGroup> groups = buildParentGroupsSet();
element = new Element(cacheKey, groups);
parentGroupsCache.put(element);
}
@SuppressWarnings("unchecked") final Set<IEntityGroup> rslt = (Set<IEntityGroup>) element.getObjectValue();
return rslt;
}
Aggregations