本文整理匯總了Java中org.apache.shiro.cache.Cache.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Cache.get方法的具體用法?Java Cache.get怎麽用?Java Cache.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.cache.Cache
的用法示例。
在下文中一共展示了Cache.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: crearCachedSessionInfo
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
public void crearCachedSessionInfo(String principal) {
try {
logger.warn(">>> 清除用戶[{}]的會話緩存", principal);
String cacheName = sessionDAO.getActiveSessionsCacheName();
Cache<String,Object> cache = sessionDAO.getCacheManager().getCache(cacheName);
/**
* @see #SimpleSessionDAO
*/
String sessionId = (String) cache.get(principal);
if(!StringUtils.isEmpty(sessionId)){
cache.remove(sessionId);
cache.remove(principal);
}
} catch (Exception e) {
logger.error(String.format(">>> 清除用戶[%s]的會話緩存發生異常: %s", principal, e.getMessage()), e);
}
}
示例2: doGetAuthorizationInfo
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* Gets the AuthorizationInfo that matches a token. This method is only called if the info is not already
* cached by the realm, so this method does not need to perform any further caching.
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
AuthorizationInfo authorizationInfo = getUncachedAuthorizationInfoFromPrincipals(principals);
Cache<String, AuthorizationInfo> idAuthorizationCache = getAvailableIdAuthorizationCache();
if (idAuthorizationCache != null) {
// Proactively cache any ID authorization info not already in cache
for (PrincipalWithRoles principal : getPrincipalsFromPrincipalCollection(principals)) {
if (idAuthorizationCache.get(principal.getId()) == null) {
cacheAuthorizationInfoById(principal.getId(), authorizationInfo);
}
}
}
return authorizationInfo;
}
示例3: getRolePermissions
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* Gets the permissions for a role. If possible the permissions are cached for efficiency.
*/
protected Collection<Permission> getRolePermissions(String role) {
if (role == null) {
return null;
}
Cache<String, RolePermissionSet> cache = getAvailableRolesCache();
if (cache == null) {
return _permissionReader.getPermissions(PermissionIDs.forRole(role));
}
RolePermissionSet rolePermissionSet = cache.get(role);
if (rolePermissionSet == null) {
Set<Permission> permissions = _permissionReader.getPermissions(PermissionIDs.forRole(role));
rolePermissionSet = new SimpleRolePermissionSet(permissions);
cache.put(role, rolePermissionSet);
}
return rolePermissionSet.permissions();
}
示例4: testLazyCacheManagerCreationWithoutCallingInit
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
@Test
public void testLazyCacheManagerCreationWithoutCallingInit() throws InterruptedException {
CacheManager ehCacheManager = cacheManager.getCacheManager();
assertNull(ehCacheManager);
//don't call init here - the ehcache CacheManager should be lazily created
//because of the default Shiro ehcache.xml file in the classpath. Just acquire a cache:
Cache<String, String> cache = cacheManager.getCache("test");
//now assert that an internal CacheManager has been created:
ehCacheManager = cacheManager.getCacheManager();
assertNotNull(ehCacheManager);
assertNotNull(cache);
cache.put("hello", "world");
String value = cache.get("hello");
assertNotNull(value);
assertEquals(value, "world");
System.out.println("Conf: " + ehCacheManager.getConfiguration().getDiskStoreConfiguration().getPath());
System.out.println("Name : " + ehCacheManager.getConfiguration().getName());
ehCacheManager.shutdown();
}
示例5: getCachedAuthenticationInfo
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* Returns any cached AuthenticationInfo corresponding to the specified token or {@code null} if there currently
* isn't any cached data.
*
* @param token the token submitted during the authentication attempt.
* @return any cached AuthenticationInfo corresponding to the specified token or {@code null} if there currently
* isn't any cached data.
* @since 1.2
*/
private AuthenticationInfo getCachedAuthenticationInfo(AuthenticationToken token) {
AuthenticationInfo info = null;
Cache<Object, AuthenticationInfo> cache = getAvailableAuthenticationCache();
if (cache != null && token != null) {
log.trace("Attempting to retrieve the AuthenticationInfo from cache.");
Object key = getAuthenticationCacheKey(token);
info = cache.get(key);
if (info == null) {
log.trace("No AuthorizationInfo found in cache for key [{}]", key);
} else {
log.trace("Found cached AuthorizationInfo for key [{}]", key);
}
}
return info;
}
示例6: getAuthorizationInfoById
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* Gets the authorization info for a user by their ID. If possible the value is cached for efficient lookup.
*/
@Nullable
private AuthorizationInfo getAuthorizationInfoById(String id) {
AuthorizationInfo authorizationInfo;
// Search the cache first
Cache<String, AuthorizationInfo> idAuthorizationCache = getAvailableIdAuthorizationCache();
if (idAuthorizationCache != null) {
authorizationInfo = idAuthorizationCache.get(id);
if (authorizationInfo != null) {
// Check whether it is the stand-in "null" cached value
if (authorizationInfo != _nullAuthorizationInfo) {
_log.debug("Authorization info found cached for id {}", id);
return authorizationInfo;
} else {
_log.debug("Authorization info previously cached as not found for id {}", id);
return null;
}
}
}
authorizationInfo = getUncachedAuthorizationInfoById(id);
cacheAuthorizationInfoById(id, authorizationInfo);
return authorizationInfo;
}
示例7: getCacheValueObject
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
public static Object getCacheValueObject(String key) {
Cache<String, Object> cache = SpringContextHelper
.getMemcache(SessionKeyConstant.SYSTEM_MEMCACHE_KEY);
if (cache == null) {
return null;
}
return cache.get(key);
}
示例8: getFromCache
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
private SimpleSession getFromCache(String sessionId) {
final Cache<String, SimpleSession> cache = this.cache;
return cache != null ? cache.get(sessionId) : null;
}
示例9: get
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* 獲取緩存的值
* @param cacheName 緩存名稱
* @param key 緩存key
* @return
*/
@Override
public Object get(String cacheName,String key){
Cache<Object, Object> cache = cacheManager.getCache(cacheName);
return cache.get(key);
}
示例10: getCachedSession
import org.apache.shiro.cache.Cache; //導入方法依賴的package包/類
/**
* Returns the Session with the specified id from the specified cache. This method simply calls
* {@code cache.get(sessionId)} and can be overridden by subclasses for custom acquisition behavior.
*
* @param sessionId the id of the session to acquire.
* @param cache the cache to acquire the session from
* @return the cached session, or {@code null} if the session wasn't in the cache.
*/
protected Session getCachedSession(Serializable sessionId, Cache<Serializable, Session> cache) {
return cache.get(sessionId);
}