Cache object method · N/cache

get()

Cache.get(options)

Retrieves a value from the cache based on a key that you provide.

Implementation
Not started
Design
Open for proposals suggest how it should read
Proposals
A
Signature
Cache.get(options)
Module
N/cache
Returns
string
Governance
1 unit if the value is present in the cache 2 units if the loader function is used
Script types
Server scripts
Version
SuiteScript 2.x, documented for 2.1; since NetSuite 2016.2
call shapefrom Oracle's parameter table
1objCache.get({2    key:    /* string, required */,3    loader: /* string or function, optional */,4    ttl:    /* number, optional */5});
Oracle reference for this method
ParameterTypeRequiredDescription
options.keystringrequiredThe key corresponding to the value to be retrieved from the cache. This value cannot be null. For example, a ZIP code can be used as the key to retrieve city names. The maximum length of a key is 4KB (4096) bytes.
options.loaderstring or functionoptionalA user-defined loader function (or name of a user-defined function) used to return the requested value when it is not present in the cache. When the loader function retrieves a value, the system automatically places that value in the cache. For this reason, you should use a loader function as the primary means of populating the cache. If the value returned by the loader function is not a string, the system uses JSON.stringify() to convert the value before it is placed in the cache and returned. The maximum size of a value that can be placed in the cache is 500KB. The callback signature for the loader is loader({key:key}) , which allows the loader to be predefined in a key-agnostic way (used to get different values for the same cache type, for example). When no loader function is specified and a value is missing from the cache, the system returns null. Note: Depending on the execution of your script, the loader function may be called multiple times for a given cache value due to the ttl. Values only remain in the cache according to ttl. If the elapsed time between Cache.get calls for a given key exceed the ttl, the loader function will be called (because the value is no longer in the cache). For an example, see Retrieve Name of a City Based on a ZIP Code Using Cache and a Custom Loader Function .
options.ttlnumberoptionalThe maximum duration, in seconds, that a value retrieved by the loader function can remain in the cache. Note that the value may be removed from the cache before the ttl limit is reached. The minimum value is 300 (five minutes) and there is no maximum. The default ttl value is no limit. Important: A cached value is not guaranteed to stay in the cache for the full duration of the ttl value. The ttl value represents the maximum time that the cached value may be stored.
B

No Mynt syntax yet.

Nothing in the language compiles to Cache.get(options) today. How should it read?

C

Competing syntax for get, from GitHub Discussions. Select two or more to compare them side by side.

All discussions

Loading proposals from GitHub…

D

Write the Mynt you wish you could write.

A good proposal shows the syntax, the SuiteScript it should become, and argues for it: why it is clearer, how it fits the rest of the language, what it makes harder.

  • Clarity. Does it say what happens, without ceremony?
  • Consistency. Does it read like load, save and Ref[field]?
  • Expressiveness. Does it cover the cases people actually write?
  • Honesty. Does it hide a NetSuite cost, such as governance, that a reader should see?

N/cache · Cache.get(options)

Suggest syntax for get