update the docs
This commit is contained in:
parent
de9906ad56
commit
581756ccc5
@ -4,20 +4,21 @@
|
|||||||
Richmedia are cached without the ttl but the rich media may have image which can expire, like aws signed url.
|
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.
|
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 on image.
|
So to avoid such situation we can define a module that will set ttl based on image.
|
||||||
|
The module must adopt behaviour `Pleroma.Web.RichMedia.Parser.TTL`
|
||||||
The module must have a `run` function and it should be registered in the config.
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```exs
|
```exs
|
||||||
defmodule MyModule do
|
defmodule MyModule do
|
||||||
def run(data, url) do
|
@behaviour Pleroma.Web.RichMedia.Parser.TTL
|
||||||
|
|
||||||
|
@impl Pleroma.Web.RichMedia.Parser.TTL
|
||||||
|
def ttl(data, url) do
|
||||||
image_url = Map.get(data, :image)
|
image_url = Map.get(data, :image)
|
||||||
# do some parsing in the url and get the ttl of the image
|
# do some parsing in the url and get the ttl of the image
|
||||||
# ttl is unix time
|
# return ttl is unix time
|
||||||
ttl = parse_ttl_from_url(image_url)
|
parse_ttl_from_url(image_url)
|
||||||
Cachex.expire_at(:rich_media_cache, url, ttl * 1000)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user