44import logging
55import pickle
66import time
7- from typing import Dict , Optional
7+ from typing import Dict , Optional , Union
88
99import httpx
1010from platformdirs import PlatformDirs
@@ -20,7 +20,7 @@ class Oembed:
2020 """Application of oEmbed."""
2121
2222 _registry : ProviderRegistry
23- _cache : Dict [consumer .RequestParameters , CachedContent ]
23+ _cache : Dict [consumer .RequestParameters , Union [ Content , CachedContent ] ]
2424 _fallback_type : bool
2525
2626 def __init__ (self , fallback_type : bool = False ): # noqa: D107
@@ -51,11 +51,17 @@ def fetch(
5151 params .max_height = max_height
5252 #
5353 now = time .mktime (time .localtime ())
54- if params in self ._cache and now <= self ._cache [params ].expired :
55- return self ._cache [params ].content
54+ if params in self ._cache :
55+ # For comptibility CachedContent
56+ val = self ._cache [params ]
57+ if isinstance (val , CachedContent ):
58+ if now <= val .expired :
59+ return val .content
60+ elif now <= val ._expired :
61+ return val
5662 content = consumer .fetch_content (api_url , params , self ._fallback_type )
5763 if content .cache_age :
58- self ._cache [params ] = CachedContent ( now + int ( content . cache_age ), content )
64+ self ._cache [params ] = content
5965 return content
6066
6167
0 commit comments