本文整理汇总了Java中org.sakaiproject.memory.api.Cache.put方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.put方法的具体用法?Java Cache.put怎么用?Java Cache.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sakaiproject.memory.api.Cache
的用法示例。
在下文中一共展示了Cache.put方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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;
}
}
示例4: readProperties
import org.sakaiproject.memory.api.Cache; //导入方法依赖的package包/类
/**
* Read in properties from the database.
*
* @param r
* The resource for which properties are to be read.
*/
public void readProperties(Connection conn, String table, String idField, Object id, ResourcePropertiesEdit p)
{
// if not properties table set, skip it
if (table == null) return;
// check we have an ID to lookup otherwise we get cross thread cache contamination.
if (id == null) return;
// the properties to fill in
final ResourcePropertiesEdit props = p;
Cache myCache = getCache(table);
String cacheKey = table + ":" + idField + ":" + id;
if ( myCache != null )
{
log.debug("CHECKING CACHE cacheKey={}", cacheKey);
Object obj = myCache.get(cacheKey);
if ( obj != null && obj instanceof ResourcePropertiesEdit )
{
// Clone the properties - do not return the real value
ResourcePropertiesEdit re = (ResourcePropertiesEdit) obj;
props.addAll(re);
log.debug("CACHE HIT cacheKey={}", cacheKey);
return;
}
}
// get the properties from the db
// ASSUME: NAME, VALUE for fields
String sql = flatStorageSql.getSelectNameValueSql(table, idField);
Object fields[] = new Object[1];
fields[0] = id;
m_sql.dbRead(conn, sql, fields, new SqlReader()
{
public Object readSqlResultRecord(ResultSet result)
{
try
{
// read the fields
String name = result.getString(1);
String value = result.getString(2);
// add to props, if we got stuff from the fields
if ((name != null) && (value != null))
{
props.addProperty(name, value);
}
// nothing to return
return null;
}
catch (SQLException e)
{
log.warn("readProperties: " + e);
return null;
}
}
});
if ( myCache != null )
{
// We don't want to put the returned value in the cache otherwise the
// caller may changes it the copy in the cache is updated too, even if
// the caller's changed copy is never persisted into the database.
ResourcePropertiesEdit cacheCopy = new BaseResourcePropertiesEdit();
cacheCopy.addAll(props);
myCache.put(cacheKey,cacheCopy);
}
}