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