Closed own2pwn closed 5 years ago
Hi @own2pw; this wrapper is not specifically meant for tokens; just anything that can "expire" and becomes invalid, hence the name.
You are right that in the tokens case the expiration is typically controlled by the backend, not the client. This makes using a "duration" pointless. However, for this particular case I added both a constructor and a setter that can take expiration dates:
// You can construct an expirable with an initial value and expiration date:
@Expirable(initialValue: "zyx987", expirationDate: date, duration: 60)
var apiToken: String?
// Whenever you refresh from your server; you set using the wrapper method:
$apiToken.set("zyx987", expirationDate: date)
If you keep using those then the duration
is never used and only the expiration date is used. I couldn't come up with any better idea for using expiration dates than this one; ideas are welcome.
I see now that the token example is not the best one; I will try to come up with something else!
Thanks you!
Wouldn't it be intuitive to have @Expirable as @Cached instead? Coz token usually isn't expired(if we're talking from the app's point of view) i.e. the server manages token's life time and client simply caches it for limited time.