緩存整個表 (Caching the entire table)


問題描述

緩存整個表 (Caching the entire table)

我們有一個 spring boot web 服務(帶有 spring 數據,hibernate),它通過從數據庫中讀取整個表並返回它來生成一個巨大的文件。這樣做需要很多時間,這比客戶設置的超時時間要長得多。所以我決定使用 ehcache 來緩存整個表的數據並從中生成文件(我知道緩存不是為此而設計的,但我沒有任何其他想法)。它的表現令人滿意。但是當我們需要對數據進行更新時,問題就來了。更新在每個記錄級別進行,但緩存存儲在整個表級別。我不確定如何讓 ehcache 查看緩存對像中的記錄並修改它們(由於某些性能原因,我不想將每一行存儲為單獨的緩存對象)。非常感謝您對此提供任何幫助。

現在,為了解決這個問題,我擺脫了 ehcache 並使用了哈希映射。這導致了很多我不喜歡的樣板代碼。

編輯:有沒有辦法連接到 ehcache 驅逐機制並手動更改緩存對象?


參考解法

方法 1:

Using the parameter timeToLiveSeconds into ehcache.xml you can specify hoy much time would the data be in cache. One option is to provide a time (for example, 24 hours), so data will be in cache for this time, and on next method call will be refreshed.

To avoid the client to do this call (because of the time spent), you can make an Spring scheduled task to call this with the same period, so the cache will be refreshed periodically.

Other way is forcing the cache to refresh when you make changes calling an especific function. So you can remove the cache, and then call the method again to re‑charge data in cache. In this link is told how to remove a cache in order to force refresh: http://forum.spring.io/forum/spring‑projects/data/55466‑how‑to‑force‑ehcache‑to‑refresh

(by falconWakachopo)

參考文件

  1. Caching the entire table (CC BY‑SA 2.5/3.0/4.0)

#caching #java #ehcache #hibernate #spring






相關問題

Heroku 上的頁面緩存技巧? (Page caching trick on Heroku?)

Array of Structs selalu lebih cepat daripada Structs of arrays? (Array of Structs are always faster than Structs of arrays?)

使用 Varnish 更改標頭中的引用者 (Change Referrer in header using Varnish)

清理 ios 中的 uiwebview 緩存 (clean uiwebview cache in ios)

緩存整個表 (Caching the entire table)

過期/緩存控制標頭的問題 (Problem with Expires/Cache-Control Headers)

強制 L1 緩存上的一些數據 (force some data on L1 cache)

Facebook API - 在服務器上緩存響應 (Facebook API - cache response on server)

ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)

如果小於 X 天,如何從磁盤讀取文件,如果舊,則重新獲取 html 文件 (How to read a file from the disk if less than X days old, if older, refetch the html file)

當您的應用服務器託管在不同的雲服務上時,如何安全地從 Firebase 託管上的 CDN 緩存中受益 (How to safely benefit from CDN caching on Firebase Hosting when your app's server is hosted on a different Cloud service)

如何使用java處理緩存中的鎖定(ConcurrentHashMap) (How to handle lock in cache (ConcurrentHashMap) using java)







留言討論