Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

howto_set_richmedia_cache_ttl_based_on_image.md 1006B

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233
  1. # How to set rich media cache ttl based on image ttl
  2. ## Explanation
  3. Richmedia are cached without the ttl but the rich media may have image which can expire, like aws signed url.
  4. In such cases the old image url (expired) is returned from the media cache.
  5. So to avoid such situation we can define a module that will set ttl based on image.
  6. The module must adopt behaviour `Pleroma.Web.RichMedia.Parser.TTL`
  7. ### Example
  8. ```exs
  9. defmodule MyModule do
  10. @behaviour Pleroma.Web.RichMedia.Parser.TTL
  11. @impl Pleroma.Web.RichMedia.Parser.TTL
  12. def ttl(data, url) do
  13. image_url = Map.get(data, :image)
  14. # do some parsing in the url and get the ttl of the image
  15. # return ttl is unix time
  16. parse_ttl_from_url(image_url)
  17. end
  18. end
  19. ```
  20. And update the config
  21. ```exs
  22. config :pleroma, :rich_media,
  23. ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl, MyModule]
  24. ```
  25. > For reference there is a parser for AWS signed URL `Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl`, it's enabled by default.