Hey everyone! Has anyone played with the cache.ge...
# suitescript
d
Hey everyone! Has anyone played with the cache.get
loader
function to return a
null
or
undefined
to indicate NOT to cache a value?
2
m
I just throw an error to make sure it's not cached.
d
We generally don’t use the `loader`—not just for this reason, but also because it doesn’t let us set the TTL. So we stick with the `get`/`put` approach instead.
c
We have a wrapper that acts similar to the loader that does the get/set with a ttl. Under the hood it performs the get -> null check/get return -> run loader anonymous function -> set/return
m
Where does is say that ttl can't be set with the loader function? Am I not understanding something?
d
@Marvin — consider caching the access token. A successful token response typically includes a TTL. Since the token is retrieved inside the loader (so we don’t know the TTL ahead of time), we can set the cache TTL from within the loader itself. (Only another reason not to use the
loader
function of get
Further,
loader
is not asynchronous.
So, in short, build your own cache loading mechanism.
m
I get what you are saying now you want to determine TTL based on something calculated within loader.
d
That's right