简体   繁体   中英

Sidekiq Workers Not Expiring Cache

Our architecture has dedicated servers that only run Sidekiq worker processes, ie there is no app server. We have some model caching going on - all calls to Rails.cache inside models specify an expires_in value but the expired caches are not being cleared.

Occasionally the disk inodes fill up becasue the tmp/cache is never getting cleaned up.

The fix is simple - run a cron job for tmp:cache:clear , but maybe the community can offer some guidance and understanding on this scenario w/r to how Rails clears expired model cache keys especially when Sidekiq workers are the only thing running on a server.

Expiration is handled by the Cache Store, if it supports such thing. Rails' default cache store (file store) is simple, it doesn't know much. What you are doing, manually clearing the cache is what the docs (below) suggest.

You can try Redis or Memcached , they know how to expire things.

An excerpt from ActiveSupport::Cache::FileStore

2.4 ActiveSupport::Cache::FileStore

This cache store uses the file system to store entries. The path to the directory where the store files will be stored must be specified when initializing the cache.

As the cache will grow until the disk is full, it is recommended to periodically clear out old entries.

This is the default cache store implementation (at "#{root}/tmp/cache/") if no explicit config.cache_store is supplied.

And another one from ActiveSupport::Cache::Store

:expires_in - This option sets an expiration time in seconds for the cache entry, if the cache store supports it, when it will be automatically removed from the cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM