mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
Instead of using ngx_cache_purge which was buggy, we are trying proxy_cache_bypass, which is internal to nginx. This is A Good Thing (assuming it works), because when we call HEAD on the purge item, it also warms the cache for us, which the previous system did not do. We want newly updated files to cache warm, because they are expected to be used quickly.
29 lines
770 B
Ruby
29 lines
770 B
Ruby
require 'open-uri'
|
|
|
|
class PurgeCacheWorker
|
|
HTTP_TIMEOUT = 5
|
|
include Sidekiq::Worker
|
|
sidekiq_options queue: :purgecache, retry: 1000, backtrace: false, average_scheduled_poll_interval: 1
|
|
|
|
sidekiq_retry_in do |count|
|
|
return 10 if count < 10
|
|
180
|
|
end
|
|
|
|
def perform(proxy_ip, username, path)
|
|
# Must always have a forward slash
|
|
path = '/' + path if path[0] != '/'
|
|
|
|
url = Addressable::URI.encode_component(
|
|
"http://#{proxy_ip}#{path}",
|
|
Addressable::URI::CharacterClasses::QUERY
|
|
)
|
|
begin
|
|
RestClient::Request.execute method: :head, url: url, timeout: HTTP_TIMEOUT, headers: {
|
|
host: URI::encode("#{username}.neocities.org"),
|
|
cache_purge: '1'
|
|
}
|
|
rescue RestClient::ResourceNotFound
|
|
end
|
|
end
|
|
end
|