ある時点で複数のリクエストに対してブロッキング キャッシュを実装したいと考えています。
現在、私はこれを持っています:
ファイルAppConfig.javaで、キャッシュマネージャーを定義しました
@EnableCaching
@Configuration
public class AppConfig implements WebMvcConfigurer {
@Bean
public CacheManager cacheManager() {
return new EhCacheCacheManager(Objects.requireNonNull(ehCacheCacheManager().getObject()));
}
@Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
cacheManagerFactoryBean.setShared(true);
return cacheManagerFactoryBean;
}
}
ファイルからの BlockingCache 定義は次のとおりです。BlockingCacheDecoratorFactory.java
@Component
public class BlockingCacheDecoratorFactory extends CacheDecoratorFactory {
public Ehcache createDecoratedEhcache(final Ehcache cache, final Properties properties) {
return new BlockingCache(cache);
}
public Ehcache createDefaultDecoratedEhcache(final Ehcache cache, final Properties properties) {
return new BlockingCache(cache);
}
}
ehache.xmlからxml構成ファイルにデコレータを追加しましたresources
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">
<cache name="findConcurrentById"
eternal="false"
maxEntriesLocalHeap="20000"
timeToLiveSeconds="1800"
memoryStoreEvictionPolicy="LRU">
<cacheDecoratorFactory class="com.site.configuration.BlockingCacheDecoratorFactory"/>
</cache>
</ehcache>
そして、メソッドでキャッシュを取得したい
@Cacheable(value = "findConcurrentById", key = "#id", condition = "#result != null")
public Optional<Concurrent> findBy(Long id) {
return concurrentRepo.findBy(id);
}
しかし、まだ機能しません。私が読んだものは、私がすでに実装したもの以上のものを説明していません。私のコードで何が間違っているのか誰かが説明してくれますか?