當前位置: 首頁>>代碼示例>>Java>>正文


Java Cache類代碼示例

本文整理匯總了Java中org.apache.shiro.cache.Cache的典型用法代碼示例。如果您正苦於以下問題:Java Cache類的具體用法?Java Cache怎麽用?Java Cache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Cache類屬於org.apache.shiro.cache包,在下文中一共展示了Cache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
	}
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:18,代碼來源:ShiroCacheServiceImpl.java

示例2: getCache

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Override
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
    logger.debug("獲取名稱為: " + name + " 的RedisCache實例");

    Cache c = caches.get(name);

    if (c == null) {

        // create a new cache instance
        c = new RedisCache<K, V>(jedisClient, keyPrefix);

        // add it to the cache collection
        caches.put(name, c);
    }
    return c;
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:17,代碼來源:RedisCacheManager.java

示例3: getCache

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
  log.trace("Acquiring EhcacheShiro instance named [{}]", name);

  try {
    org.ehcache.Cache<Object, Object> cache = ensureCacheManager().getCache(name, Object.class, Object.class);

    if (cache == null) {
      log.info("Cache with name {} does not yet exist.  Creating now.", name);
      cache = createCache(name);
      log.info("Added EhcacheShiro named [{}]", name);
    } else {
      log.info("Using existing EhcacheShiro named [{}]", name);
    }

    return new EhcacheShiro<K, V>(cache);
  } catch (MalformedURLException e) {
    throw new CacheException(e);
  }
}
 
開發者ID:ehcache,項目名稱:ehcache-shiro,代碼行數:23,代碼來源:EhcacheShiroManager.java

示例4: testGetCache

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Test
public void testGetCache() throws Exception {
  EhcacheShiroManager cacheManager = new EhcacheShiroManager();

  try {
    Cache<Object, Object> someCache = cacheManager.getCache("someCache");
    Assert.assertNotNull(someCache);

    final String key = "key";
    final String value = "value";
    Assert.assertNull(someCache.put(key, value));
    Assert.assertEquals(value, someCache.get(key));
  } finally {
    cacheManager.destroy();
  }
}
 
開發者ID:ehcache,項目名稱:ehcache-shiro,代碼行數:17,代碼來源:EhcacheShiroManagerTest.java

示例5: simpleNewExists

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Test
public void simpleNewExists() {
    Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache();
    assertEquals(cache.size(), 0, "precondition: cache is empty");
    Permission p1 = mock(Permission.class);
    when(p1.toString()).thenReturn("p1");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p1));
    Collection<Permission> resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p1, "should have the first permission we added");
    assertEquals(cache.size(), 1, "side effect: cache has one element");
    Permission p2 = mock(Permission.class);
    when(p2.toString()).thenReturn("p2");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p2));
    cache.clear();
    Collection<Permission> resultPerms2 = _underTest.getRolePermissions("role");
    assertEquals(resultPerms2.iterator().next(), p2, "should have the second permission we added");
    assertEquals(cache.size(), 1, "side effect: cache still has one element");
    resultPerms2 = _underTest.getRolePermissions("role");
    assertEquals(resultPerms2.iterator().next(), p2, "should still have the second permission we added");
    assertEquals(cache.size(), 1, "side effect: cache still has one element");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:ApiKeyRealmTest.java

示例6: simpleNowEmpty

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Test
public void simpleNowEmpty() {
    Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache();
    assertEquals(cache.size(), 0, "precondition: cache is empty");
    Permission p1 = mock(Permission.class);
    when(p1.toString()).thenReturn("p1");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p1));
    Collection<Permission> resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p1, "should have the first permission we added");
    assertEquals(cache.size(), 1, "side effect: cache has one element");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.<Permission>newHashSet());
    cache.clear();
    resultPerms = _underTest.getRolePermissions("role");
    assertTrue(resultPerms.isEmpty(), "now should have empty");
    assertEquals(cache.size(), 1, "side effect: cache has empty permission");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:17,代碼來源:ApiKeyRealmTest.java

示例7: pseudoConcurrentNewExists

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Test
public void pseudoConcurrentNewExists() {
    Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache();
    assertEquals(cache.size(), 0, "precondition: cache is empty");
    Permission p1 = mock(Permission.class);
    when(p1.toString()).thenReturn("p1");
    Permission p2 = mock(Permission.class);
    when(p2.toString()).thenReturn("p2");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p1), Sets.newHashSet(p2));
    Collection<Permission> resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p1, "should have the first permission we added");
    assertEquals(cache.size(), 1, "side effect: cache has one element");
    resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p2, "should have the last permission we added");
    assertEquals(cache.size(), 1, "side effect: cache has one element");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:17,代碼來源:ApiKeyRealmTest.java

示例8: pseudoConcurrentNewThenCacheFlush

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@Test
public void pseudoConcurrentNewThenCacheFlush() {
    Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache();
    assertEquals(cache.size(), 0, "precondition: cache is empty");
    Permission p1 = mock(Permission.class);
    when(p1.toString()).thenReturn("p1");
    Permission p2 = mock(Permission.class);
    when(p2.toString()).thenReturn("p2");
    when(_permissionManager.getPermissions(PermissionIDs.forRole("role")))
            .thenReturn(Sets.newHashSet(p1))
            .thenReturn(Sets.newHashSet(p2));
    Collection<Permission> resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p1, "should have the last permission we added");
    assertEquals(cache.size(), 1, "side effect: cache has one element");
    cache.clear();
    resultPerms = _underTest.getRolePermissions("role");
    assertEquals(resultPerms.iterator().next(), p2, "should again have the last permission we added");
    assertEquals(cache.size(), 1, "side effect: cache again has one element");
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:20,代碼來源:ApiKeyRealmTest.java

示例9: 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;
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:ApiKeyRealm.java

示例10: 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();
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:24,代碼來源:ApiKeyRealm.java

示例11: clearAllCachedAuthorizationInfo

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
/**
 * 清除所有用戶授權信息緩存.
 */
public void clearAllCachedAuthorizationInfo() {
	if (logger.isDebugEnabled()) {
		logger.debug("clearAllCachedAuthorizationInfo() - start"); //$NON-NLS-1$
	}

	Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();
	if (cache != null) {
		for (Object key : cache.keys()) {
			cache.remove(key);
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("clearAllCachedAuthorizationInfo() - end"); //$NON-NLS-1$
	}
}
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:20,代碼來源:ShiroCustomRealm.java

示例12: 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();
}
 
開發者ID:nebrass,項目名稱:pairing-shiro-javaee7,代碼行數:25,代碼來源:EhCacheManagerTest.java

示例13: getAuthorizationCacheLazy

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
/**
 * 因為{@link AuthorizingRealm#getAuthorizationCacheLazy()}方法為 private,當前類的{@link #getAuthorizationInfo}
 * 方法不能沒權限訪問,所以把{@link AuthorizingRealm#getAuthorizationCacheLazy()}方法Copy一份
 * @return
 */
private Cache<Object, AuthorizationInfo> getAuthorizationCacheLazy() {
	if (getAuthorizationCache() == null) {
		if (log.isDebugEnabled()) {
			log.debug("No authorizationCache instance set.  Checking for a cacheManager...");
		}
		
		CacheManager cacheManager = getCacheManager();
		if (cacheManager != null) {
			String cacheName = getAuthorizationCacheName();
			if (log.isDebugEnabled()) {
				log.debug("CacheManager [{}] has been configured.  Building authorization cache named [{}]",
						cacheManager, cacheName);
			}
			setAuthorizationCache(cacheManager.getCache(cacheName));
		} else {
			if (log.isInfoEnabled()) {
				log.info("No cache or cacheManager properties have been set.  Authorization cache cannot be obtained.");
			}
		}
	}
	return getAuthorizationCache();
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:28,代碼來源:DefaultCasRealm.java

示例14: getCache

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <K, V> Cache<K, V> getCache(String name) throws CacheException {
    logger.debug(" redis cache name is  " + name);
    synchronized (this) {
        Cache<K, V> cache = caches.get(name);
        if (cache == null) {
            int expire = otherExpire;
            if (RedisSessionDAO.ACTIVE_SESSION_CACHE_NAME.equals(name)) {
                expire = sessionExpire;
            }
            cache = new RedisCache<K, V>(redisManager, expire);
            caches.put(name, cache);
        }
        return cache;
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:18,代碼來源:RedisCacheManager.java

示例15: getAuthenticationCacheLazy

import org.apache.shiro.cache.Cache; //導入依賴的package包/類
/**
 * Checks to see if the authenticationCache class attribute is null, and if so, attempts to acquire one from
 * any configured {@link #getCacheManager() cacheManager}.  If one is acquired, it is set as the class attribute.
 * The class attribute is then returned.
 *
 * @return an available cache instance to be used for authentication caching or {@code null} if one is not available.
 * @since 1.2
 */
private Cache<Object, AuthenticationInfo> getAuthenticationCacheLazy() {

    if (this.authenticationCache == null) {

        log.trace("No authenticationCache instance set.  Checking for a cacheManager...");

        CacheManager cacheManager = getCacheManager();

        if (cacheManager != null) {
            String cacheName = getAuthenticationCacheName();
            log.debug("CacheManager [{}] configured.  Building authentication cache '{}'", cacheManager, cacheName);
            this.authenticationCache = cacheManager.getCache(cacheName);
        }
    }

    return this.authenticationCache;
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:26,代碼來源:AuthenticatingRealm.java


注:本文中的org.apache.shiro.cache.Cache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。