儘管配置中已設置了到期時間,但數據仍未從Ignite高速緩存中逐出。我注意到當我使用SQL將數據插入緩存表時,發生此問題。如果通過SQL插入,Ignite高速緩存條目不會被驅逐
emplCache.query(new SqlFieldsQuery(
"CREATE TABLE Employee (id LONG PRIMARY KEY, firstName VARCHAR, lastName VARCHAR,
salary DECIMAL, gender VARCHAR)")).getAll();
SqlFieldsQuery insertqry = new SqlFieldsQuery("INSERT INTO Employee (id, firstName,
lastName, salary, gender) values (?, ?, ?, ?, ?)");
emplCache.query(insertqry.setArgs(Long.toString(count), words[1], words[2],
words[3], words[4])).getAll();
這是我如何配置屆滿:
CacheConfiguration<?, ?> cfg = new CacheConfiguration<>(cacheName);
cfg.setCacheMode(CacheMode.PARTITIONED);
cfg.setName(cacheName);
cfg.setSqlSchema("PUBLIC");
cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, 1)));
然而,我沒有看到這個問題,如果我使用dataStreamer插入數據。
IgniteDataStreamer<Integer, Employee> stmr = ignite.dataStreamer(cfg.getName())
stmr.addData(id, emp);
我錯過了一些配置設置嗎?
[PS]嘗試葉甫的回答後,執行以下操作:
// This is a util method that returns a cache config for the given cache name and the expiry time in seconds
CacheConfiguration<?, ?> cfg = CacheConfig.getCacheConfig("emplCache", 1);
IgniteCache<?, ?> emplCache = ignite.getOrCreateCache(cfg);
emplCache.query(new SqlFieldsQuery(
"CREATE TABLE Employee (id LONG PRIMARY KEY, firstName VARCHAR, lastName VARCHAR, salary DECIMAL, gender VARCHAR)"
+ "WITH \"template=emplCache\" ")).getAll();
現在我得到這個例外是緩存中不存在。但是我想創建緩存後創建表:
Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.internal.processors.query.IgniteSQLException: Cache doesn't exist: emplCache
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:807)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:765)
at com.demo.ignite.svc.CsvStreamer.main(CsvStreamer.java:33)
Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Cache doesn't exist: emplCache
at org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.convert(DdlStatementsProcessor.java:277)
at org.apache.ignite.internal.processors.query.h2.ddl.DdlStatementsProcessor.runDdlStatement(DdlStatementsProcessor.java:221)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1331)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1815)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1813)
at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2293)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:1820)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:795)
請在您配置的地方共享緩存配置EvictionPolicy –
編輯我的問題以包含我在代碼中設置的確切配置。除此之外,我還沒有做過更多的配置。我假設ExpiryPolicy與EvictionPolicy相同。或者我錯了? –