You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Ignite:SQLQuery与TouchedExpiryPolicy协同异常咨询

Troubleshooting TouchedExpiryPolicy + SQLQuery Cache Expiry Quirk

I’ve run into this exact issue before with certain cache implementations—turns out it’s not exactly a "compatibility bug" but rather a nuance in how sqlQuery interacts with the expiry policy’s access tracking. Let me break this down:

Why this is happening

The core problem lies in how sqlQuery handles cache entry access compared to other methods:

  • When you use scanQuery or cache.getAll, the cache directly accesses each individual entry in the store. Every access triggers the TouchedExpiryPolicy’s logic to reset the expiry timer for that entry, which is exactly what you’d expect.
  • sqlQuery, however, often uses an optimized path—like querying an underlying index or a snapshot of cached data—instead of hitting each entry directly. This means the cache never registers those query results as "active accesses" to the individual entries. As a result, their expiry timers keep counting down from the original creation time, so they expire exactly 10 seconds after creation no matter how many times you run the query.

Fixes you can try right now

  1. Manually touch entries after running sqlQuery
    The simplest workaround is to loop through your query results and explicitly call the cache’s touch method for each entry’s key. This manually resets the expiry timer just like a direct access would:
    // Example code (adjust based on your cache API)
    List<YourCachedObject> results = cache.sqlQuery("SELECT * FROM YourTable WHERE ...");
    for (YourCachedObject item : results) {
        cache.touch(item.getCacheKey());
    }
    
  2. Check your cache provider’s query settings
    Some cache tools (like Hazelcast, Ignite, etc.) have configuration flags that force query operations to update entry access timestamps. Look for settings named something like track-query-access or expiry-on-query in your provider’s docs—enabling this might fix the issue without manual code changes.
  3. Switch to an access-aware expiry policy (if supported)
    If your cache provider offers it, consider using an AccessedExpiryPolicy instead (or a variant explicitly designed to account for query-based access). Some policies are built to recognize when entries are retrieved via queries and reset their timers automatically.

How to verify the fix

Enable debug logging for your cache’s expiry and access events. You’ll notice that before the fix, sqlQuery doesn’t log any "entry accessed" events, while scanQuery does. After applying your fix, those events should appear for sqlQuery results, confirming the expiry timers are being reset correctly.

内容的提问来源于stack exchange,提问作者Mitn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:46:29