onRemoval metodu
Örnek
Şöyle yaparız.
Şöyle yaparız
Örnek
Şöyle yaparız.
CacheLoader<Key, DatabaseConnection> loader = new CacheLoader<Key,DatabaseConnection> (){
public DatabaseConnection load(Key key) throws Exception {
return openConnection(key);
}
};
RemovalListener<Key, DatabaseConnection> removalListener = new
RemovalListener<Key,DatabaseConnection>() {
public void onRemoval(RemovalNotification<Key, DatabaseConnection> removal) {
DatabaseConnection conn = removal.getValue();
conn.close(); // tear down properly
}
};
return CacheBuilder.newBuilder()
.expireAfterWrite(2, TimeUnit.MINUTES)
.removalListener(removalListener)
.build(loader);
ÖrnekŞöyle yaparız
CacheBuilder.newBuilder().maximumSize(250)
.expireAfterWrite(15, TimeUnit.SECONDS)
.removalListener(new RemovalListener<String, Path>(){
@Override
public void onRemoval(RemovalNotification<String, Path> notification){
deleteTemporaryFile(notification.getValue());
}
}).build();
Hiç yorum yok:
Yorum Gönder