-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support limited cache size and automatic cleanup #13
Comments
PR for the first option has been made: #14 |
And the second part can be found in #15 |
@Qqwy I have reviewed both PRs. As mentioned inline, I do see a use case for both, but I am a little hesitant to add them without further discussion as - although optional - seem to add quite a bit of overhead the average user may not want/be aware of. I have not seen any other cache backends implementing them, have you? The |
And thank you very much for the contribution, btw. It's really appreciated! |
We're running into a similar issue -- our cache grows by huge margin and it seems to be happening because of It wouldn't be suitable for us to clean cache on write_entry as @dim already mentioned -- it will affect performance. Instead, I was thinking of modifying cleanup method to introduce ability to purge records that are older than 1 month (this could be configurable). This could be determined based on created_at value. |
@skatkov I can work with that, would you be able to submit a PR? |
Alternatively, you could just have a background worker/task/job doing: m = ActiveSupport::Cache::DatabaseStore::Model
m.where(m.arel_table[:updated_at].lt(1.month.ago)).delete_all |
@dim will submit a PR with a fix. |
Should we close this issue? Here is PR that solved an issue at hand: |
Hi there! This is a very well-written implementation of a SQL-based ActiveSupport::Cache::Store backend. 💚
By reading through the source code, I came across the cleanup method.
It seems like currently you'd have to call this manually. (Or e.g. put it in a
whenever
-based periodic task to make sure it happens ever so often).Very much related, it might happen that the cache becomes very large (by being filled with many objects with no
expires_in
or one that is relatively far in the future).It would be relatively straightforward to add the following two options:
auto_cleanup:
option which, when true, will always (in anensure
block for good measure) callcleanup
at the end of write_entry.max_size:
option which, when not-nil, will when callingwrite_entry
while going over the limit, first runcleanup
and if that is not enough, remove the oldest non-expired record (based oncreated_at
).What do you think?
I'd love to contribute a PR for these changes 👍 !
The text was updated successfully, but these errors were encountered: