本文整理汇总了Java中org.sakaiproject.memory.api.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于org.sakaiproject.memory.api包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPosts
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
public List<Post> getPosts(QueryBean query) throws Exception {
Cache cache = sakaiProxy.getCache(POST_CACHE);
// Social commons caches are keyed on the owner's user id
String key = (query.isUserSite) ? query.callerId : query.commonsId;
List<Post> posts = (List<Post>) cache.get(key);
if (posts == null) {
log.debug("Cache miss or expired on id: {}", key);
if (query.isUserSite) {
log.debug("Getting posts for a user site ...");
query.fromIds.add(query.callerId);
query.fromIds.addAll(getConnectionUserIds(sakaiProxy.getCurrentUserId()));
}
List<Post> unfilteredPosts = persistenceManager.getAllPost(query, true);
cache.put(key, unfilteredPosts);
return commonsSecurityManager.filter(unfilteredPosts, query.siteId, query.embedder);
} else {
log.debug("Cache hit on id: {}", key);
return commonsSecurityManager.filter(posts, query.siteId, query.embedder);
}
}
示例2: getCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
/**
* Get the cache manager for this table
*
* @param table
*/
protected Cache getCache(String table)
{
if ( table == null ) return null;
String config = ServerConfigurationService.getString("DbFlatPropertiesCache");
// Default is :all:
if ( config == null || config.trim().length() <= 0 ) config = ":all:";
if ( config.indexOf(":none:") >= 0 ) return null;
if ( config.indexOf(":all:") < 0 )
{
if ( config.indexOf(":"+table+":") < 0 ) return null;
}
String cacheName = CACHE_NAME_PREFIX+table;
MemoryService memoryService = MemoryServiceLocator.getInstance();
if ( memoryService == null ) return null;
Cache myCache = memoryService.newCache(cacheName);
return myCache;
}
示例3: writeProperties
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
/**
* Replace any properties for this resource with the resource's current set of properties.
*
* @param r
* The resource for which properties are to be written.
*/
public void writeProperties(final String table, final String idField, final Object id, final String extraIdField, final String extraId,
final ResourceProperties props, final boolean deleteFirst)
{
// if not properties table set, skip it
if (table == null) return;
if (props == null) return;
Cache myCache = getCache(table);
String cacheKey = table + ":" + idField + ":" + id;
if ( myCache != null )
{
log.debug("CACHE REMOVE cacheKey={} cache={}", cacheKey, myCache);
myCache.remove(cacheKey);
}
// do this in a transaction
m_sql.transact(new Runnable()
{
public void run()
{
writePropertiesTx(table, idField, id, extraIdField, extraId, props, deleteFirst);
}
}, "writeProperties:" + id);
}
示例4: testCacheRealmPermsChangedSimple
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
@Test
public void testCacheRealmPermsChangedSimple() throws GroupNotDefinedException {
Cache cache = mock(Cache.class);
when(memoryService.getCache("org.sakaiproject.authz.api.SecurityService.cache")).thenReturn(cache);
sakaiSecurity.init();
AuthzGroup group = new AuthzGroupBuilder(authzGroupService, "/site/1")
.addMember("1", "role", true)
.build();
// This collects all the flushes
Set<String> flushed = new HashSet<>();
doAnswer(s -> flushed.addAll(s.getArgument(0))).when(cache).removeAll(any());
sakaiSecurity.cacheRealmPermsChanged("/realm//site/1", singleton("role"), singleton("function"));
assertThat(flushed, containsInAnyOrder("[email protected]@@[email protected]/site/1"));
}
示例5: testCacheRealmPermsChangedMultiple
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
@Test
public void testCacheRealmPermsChangedMultiple() throws GroupNotDefinedException {
Cache cache = mock(Cache.class);
when(memoryService.getCache("org.sakaiproject.authz.api.SecurityService.cache")).thenReturn(cache);
sakaiSecurity.init();
AuthzGroup group = new AuthzGroupBuilder(authzGroupService, "/site/1")
.addMember("user1", "role1", true)
.addMember("user2", "role2", true)
.build();
// This collects all the flushes
Set<String> flushed = new HashSet<>();
doAnswer(s -> flushed.addAll(s.getArgument(0))).when(cache).removeAll(any());
sakaiSecurity.cacheRealmPermsChanged("/realm//site/1", singleton("role"), new HashSet<>(Arrays.asList("function1", "function2")));
assertThat(flushed, containsInAnyOrder(
"[email protected]@@[email protected]/site/1",
"[email protected]@@[email protected]/site/1",
"[email protected]@@[email protected]/site/1",
"[email protected]@@[email protected]/site/1"
));
}
示例6: testCacheRealmPermsChangedSimpleSV
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
@Test
public void testCacheRealmPermsChangedSimpleSV() throws GroupNotDefinedException {
Cache cache = mock(Cache.class);
when(memoryService.getCache("org.sakaiproject.authz.api.SecurityService.cache")).thenReturn(cache);
when(serverConfigurationService.getString(eq("studentview.roles"), anyString())).thenReturn("student");
sakaiSecurity.init();
AuthzGroup group = new AuthzGroupBuilder(authzGroupService, "/site/1")
.addMember("1", "role", true)
.addMember("2", "student", true)
.build();
// This collects all the flushes
Set<String> flushed = new HashSet<>();
doAnswer(s -> flushed.addAll(s.getArgument(0))).when(cache).removeAll(any());
sakaiSecurity.cacheRealmPermsChanged("/realm//site/1", singleton("role"), singleton("function"));
assertThat(flushed, containsInAnyOrder("[email protected]@@[email protected]/site/1", "[email protected]@@[email protected]/site/1"));
}
示例7: initializeMockCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
private void initializeMockCache(){
Cache mock = EasyMock.createMock(Cache.class);
hierarchyService.setCache(mock);
EasyMock.expect(mock.containsKey(EasyMock.anyObject())).andReturn(false).anyTimes();
mock.put(EasyMock.anyObject(),EasyMock.anyObject());
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(mock);
}
示例8: getCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
public Cache getCache(String cache) {
try {
return memoryService.getCache(cache);
} catch (Exception e) {
log.error("Exception whilst retrieving '" + cache + "' cache. Returning null ...", e);
return null;
}
}
示例9: getCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
private Cache getCache(String name) {
try {
return memoryService.getCache(name);
} catch (Exception e) {
log.error("Exception whilst retrieving '" + name + "' cache. Returning null ...", e);
return null;
}
}
示例10: getCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
private Cache getCache(String cache) {
try {
Cache c = memoryService.getCache(cache);
if (c == null) {
c = memoryService.createCache(cache, new SimpleConfiguration(0));
}
return c;
} catch (Exception e) {
log.error("Exception whilst retrieving '" + cache + "' cache. Returning null ...", e);
return null;
}
}
示例11: getSearchIndex
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public Map<String, String> getSearchIndex(String siteId) {
try {
// Try and load the sorted memberships from the cache
Cache cache = memoryService.getCache(SEARCH_INDEX_CACHE);
if (cache == null) {
cache = memoryService.createCache(SEARCH_INDEX_CACHE, new SimpleConfiguration(0));
}
Map<String, String> index
= (Map<String, String>) cache.get(siteId);
if (index == null) {
index = new HashMap<String, String>();
for (User user : getSiteUsers(siteId)) {
index.put(user.getDisplayName(), user.getId());
}
cache.put(siteId, index);
}
return index;
} catch (Exception e) {
log.error("Exception whilst retrieving search index for site '" + siteId + "'. Returning null ...", e);
return null;
}
}
示例12: update
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
public void update(Observable o, Object arg) {
if (arg instanceof Event) {
Event event = (Event) arg;
String eventName = event.getEvent();
if (SiteService.SECURE_UPDATE_SITE_MEMBERSHIP.equals(eventName)
|| SiteService.SECURE_UPDATE_GROUP_MEMBERSHIP.equals(eventName)) {
log.debug("Site membership or groups updated. Clearing caches ...");
String siteId = event.getContext();
Cache enrollmentsCache = getCache(ENROLLMENTS_CACHE);
enrollmentsCache.remove(siteId);
Cache searchIndexCache = memoryService.getCache(SEARCH_INDEX_CACHE);
searchIndexCache.remove(siteId);
Cache membershipsCache = getCache(MEMBERSHIPS_CACHE);
synchronized(this) {
membershipsCache.remove(siteId);
Site site = getSite(siteId);
if (site != null) {
Set<Role> roles = site.getRoles();
for (Group group : site.getGroups()) {
String gId = group.getId();
membershipsCache.remove(siteId + "#" + gId);
for (Role role : roles) {
membershipsCache.remove(siteId + "#" + gId + "#" + role.getId());
}
}
}
}
}
}
}
示例13: getCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
@Override
public Cache getCache(String cacheName) {
Cache c = caches.get(cacheName);
if (c == null) {
c = new org.sakaiproject.memory.mock.Cache(cacheName);
caches.put(cacheName, c);
}
return c;
}
示例14: setCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
public void setCache(Cache cache) {
this.cache = cache;
}
示例15: setCache
import org.sakaiproject.memory.api.Cache; //导入依赖的package包/类
public void setCache(Cache cache){
this.cache = cache;
}