experimental_createPersister fixed expiresAt instead of maxAge #8650
Unanswered
NicholasKuchiniski
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, i work in finances and due to some compliance reasons, certain types of informations can only be cached until a given period, i'm trying to achieve that with
experimental_createPersister
and playing with themaxAge
property, but i wasn't able to figure it out a way to do that using it.Basically what i need is to persist the
maxAge
in the query and retrieve it when verifying if it is expired, this way, for example:(Considering that i can only keep the information during the current day)
If i make a query at 23 pm, i would have 60 minutes of maxAge
If i make a query at 00:01, i would have 23 hours and 59 minutes of maxAge
The current implementation only allows me to define
maxAge
when creating the persister, so i can't do something like that, by the time someone tries to use the second query (00:01), the max age would be 23 hours and 59 minutes so the query made at 23pm would still be valid.The idea i have is to persist the
maxAge
(which in my case i created another property inside the query metadata with the nameexpiresAt
) inside the query and if this field is present, instead of relying on `maxAge. to determine if the query is expired or not, i would use it to compare the current date.Another possible implementation would be to have a TTL in the query metadata so i can build this TTL in a query basis calculating how many time i have until the period where i want to consider the query expired (just like the TTL property works in Redis or DynamoDB, for example), then we just have to see how many time has passed between the query fetch and the current date, since the TTL would be persisted in the query itself, even if i am at a different day, since it would be relative to the current Date in the fetch moment, the query would still be invalidated since the number would be lower the closer i get to the date were i want to expiry the query in the cache.
I'm currently using this
patch-package
in my code to achieve that and it seems to be working:But i would like to hear of the community if this is something useful for the
exprimental_createPersister
Beta Was this translation helpful? Give feedback.
All reactions