

This article introduces a caching mechanism using both memory cache and memcached, which is effective when building media sites and their APIs.
Both middleware, such as memcached (Redis), and memory-based caching mechanisms have their own characteristics.
Rails.cache
because it can be shared by multiple processes.The cache structure is as follows:
This allows you to share the cache while limiting the amount of access to the memcached.
In addition, frequently accessed data can take advantage of the fast response of the memory cache.
The process of web application (PUMA) implements a mechanism to clear the cache after a certain time elapses in after_action
of application_controller.rb
, and it clears the cache periodically.
In the process of an active job, a mechanism to clear the cache is implemented in after_perform
of application_job.rb
after a certain time elapses, and the cache is cleared periodically.