Add cache cleaning and preheating

This commit is contained in:
Eugene Burmakin 2024-12-23 00:27:42 +01:00
parent 6eb3341133
commit d640af4036
3 changed files with 34 additions and 2 deletions

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.21.1 - 2024-12-23
### Added
- Cache cleaning and preheating upon application start.
# 0.21.0 - 2024-12-20
⚠️ This release introduces a breaking change. ⚠️

24
app/services/cache/clean.rb vendored Normal file
View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
class Cache::Clean
class << self
def call
Rails.logger.info('Cleaning cache...')
delete_version_cache
delete_years_tracked_cache
Rails.logger.info('Cache cleaned')
end
private
def delete_version_cache
Rails.cache.delete(CheckAppVersion::VERSION_CACHE_KEY)
end
def delete_years_tracked_cache
User.find_each do |user|
Rails.cache.delete("dawarich/user_#{user.id}_years_tracked")
end
end
end
end

View file

@ -6,6 +6,8 @@ require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
# Clear the cache of the application version
# Clear the cache
Cache::Clean.call
Rails.cache.delete(CheckAppVersion::VERSION_CACHE_KEY)
# Preheat the cache
Cache::PreheatingJob.perform_later