forked from AkkomaGang/akkoma
Add ability to invalidate cache entries for Apache
This commit is contained in:
parent
3078e62488
commit
003402df40
4 changed files with 50 additions and 3 deletions
|
@ -438,7 +438,9 @@
|
||||||
headers: [],
|
headers: [],
|
||||||
options: []
|
options: []
|
||||||
|
|
||||||
config :pleroma, Pleroma.Web.MediaProxy.Invalidation.Script, script_path: nil
|
config :pleroma, Pleroma.Web.MediaProxy.Invalidation.Script,
|
||||||
|
script_path: nil,
|
||||||
|
url_format: nil
|
||||||
|
|
||||||
# Note: media preview proxy depends on media proxy to be enabled
|
# Note: media preview proxy depends on media proxy to be enabled
|
||||||
config :pleroma, :media_preview_proxy,
|
config :pleroma, :media_preview_proxy,
|
||||||
|
|
|
@ -321,9 +321,10 @@ This section describe PWA manifest instance-specific values. Currently this opti
|
||||||
#### Pleroma.Web.MediaProxy.Invalidation.Script
|
#### Pleroma.Web.MediaProxy.Invalidation.Script
|
||||||
|
|
||||||
This strategy allow perform external shell script to purge cache.
|
This strategy allow perform external shell script to purge cache.
|
||||||
Urls of attachments pass to script as arguments.
|
Urls of attachments are passed to the script as arguments.
|
||||||
|
|
||||||
* `script_path`: path to external script.
|
* `script_path`: Path to the external script.
|
||||||
|
* `url_format`: Set to `:htcacheclean` if using Apache's htcacheclean utility.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|
25
installation/apache-cache-purge.sh.example
Executable file
25
installation/apache-cache-purge.sh.example
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# A simple shell script to delete a media from Apache's mod_disk_cache.
|
||||||
|
|
||||||
|
SCRIPTNAME=${0##*/}
|
||||||
|
|
||||||
|
# mod_disk_cache directory
|
||||||
|
CACHE_DIRECTORY="/tmp/pleroma-media-cache"
|
||||||
|
|
||||||
|
## Removes an item via the htcacheclean utility
|
||||||
|
## $1 - the filename, can be a pattern .
|
||||||
|
## $2 - the cache directory.
|
||||||
|
purge_item() {
|
||||||
|
htcacheclean -p "${2}" "${1}"
|
||||||
|
} # purge_item
|
||||||
|
|
||||||
|
purge() {
|
||||||
|
for url in "$@"
|
||||||
|
do
|
||||||
|
echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)"
|
||||||
|
purge_item "$url" $CACHE_DIRECTORY
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
purge "$@"
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.Script do
|
||||||
def purge(urls, opts \\ []) do
|
def purge(urls, opts \\ []) do
|
||||||
args =
|
args =
|
||||||
urls
|
urls
|
||||||
|
|> format_urls(Keyword.get(opts, :url_format))
|
||||||
|> List.wrap()
|
|> List.wrap()
|
||||||
|> Enum.uniq()
|
|> Enum.uniq()
|
||||||
|> Enum.join(" ")
|
|> Enum.join(" ")
|
||||||
|
@ -40,4 +41,22 @@ defp handle_result(error, _) do
|
||||||
Logger.error("Error while cache purge: #{inspect(error)}")
|
Logger.error("Error while cache purge: #{inspect(error)}")
|
||||||
{:error, inspect(error)}
|
{:error, inspect(error)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_urls(urls, :htcacheclean) do
|
||||||
|
urls
|
||||||
|
|> Enum.map(fn url ->
|
||||||
|
uri = URI.parse(url)
|
||||||
|
|
||||||
|
query =
|
||||||
|
if !is_nil(uri.query) do
|
||||||
|
"?" <> uri.query
|
||||||
|
else
|
||||||
|
"?"
|
||||||
|
end
|
||||||
|
|
||||||
|
uri.scheme <> "://" <> uri.host <> ":#{inspect(uri.port)}" <> uri.path <> query
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_urls(urls, _), do: urls
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue