summaryrefslogtreecommitdiff
path: root/docs/config/howto_set_richmedia_cache_ttl_based_on_image.md
diff options
context:
space:
mode:
authorSachin Joshi <satchin.joshi@gmail.com>2019-07-16 22:37:36 +0545
committerSachin Joshi <satchin.joshi@gmail.com>2019-07-17 00:20:34 +0545
commit18234cc44e6bc989e3e3cf15714c54b4fa05b9dd (patch)
tree4f95fdc52d7dda96396c4d83a5bf2847a63e3be4 /docs/config/howto_set_richmedia_cache_ttl_based_on_image.md
parentd3b922276138cf7aaa896d52a8e35113a40e22dc (diff)
downloadpleroma-18234cc44e6bc989e3e3cf15714c54b4fa05b9dd.tar.gz
pleroma-18234cc44e6bc989e3e3cf15714c54b4fa05b9dd.zip
add the rich media ttl based on image exp time
Diffstat (limited to 'docs/config/howto_set_richmedia_cache_ttl_based_on_image.md')
-rw-r--r--docs/config/howto_set_richmedia_cache_ttl_based_on_image.md32
1 files changed, 32 insertions, 0 deletions
diff --git a/docs/config/howto_set_richmedia_cache_ttl_based_on_image.md b/docs/config/howto_set_richmedia_cache_ttl_based_on_image.md
new file mode 100644
index 000000000..489f9ece8
--- /dev/null
+++ b/docs/config/howto_set_richmedia_cache_ttl_based_on_image.md
@@ -0,0 +1,32 @@
+# How to set rich media cache ttl based on image ttl
+## Explanation
+
+Richmedia are cached without the ttl but the rich media may have image which can expire, like aws signed url.
+In such cases the old image url (expired) is returned from the media cache.
+
+So to avoid such situation we can define a moddule that will set ttl based no image.
+
+The module must have a `run` function and it should be registered in the config.
+
+### Example
+
+```exs
+defmodule MyModule do
+ def run(data, url) do
+ image_url = Map.get(data, :image)
+ # do some parsing in the url and get the ttl of the image
+ # ttl is unix time
+ ttl = parse_ttl_from_url(image_url)
+ Cachex.expire_at(:rich_media_cache, url, ttl * 1000)
+ end
+end
+```
+
+And update the config
+
+```exs
+config :pleroma, :rich_media,
+ ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl, MyModule]
+```
+
+> For reference there is a parser for AWS signed URL `Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl`, it's enabled by default.