Guest User

Untitled

a guest
May 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Cache<String, String> tokenMap = CacheBuilder.newBuilder()
  2. //设置并发级别为8,并发级别是指可以同时写缓存的线程数
  3. .concurrencyLevel(8)
  4. //设置写缓存后8秒钟过期
  5. .expireAfterWrite(2, TimeUnit.HOURS)
  6. //设置缓存容器的初始容量为10
  7. .initialCapacity(100)
  8. //设置缓存最大容量为100,超过100之后就会按照LRU最近虽少使用算法来移除缓存项
  9. .maximumSize(1000)
  10. //设置缓存的移除通知
  11. .removalListener(new RemovalListener<Object, Object>() {
  12. @Override
  13. public void onRemoval(RemovalNotification<Object, Object> notification) {
  14. System.out.println(notification.getKey() + " was removed, cause is " + notification.getCause());
  15. }
  16. })
  17. .build();
Add Comment
Please, Sign In to add comment