Cache.put(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Puts a value into the cache. If the value provided is not a string, the system uses JSON.stringify() to convert the value to a string.

Note:

You can also put a value into the cache by using the Cache.get(options) method with its options.loader parameter. Cached data is no persistent, so you should consider using the Cache.get(options) method with the options.loader parameter to set and retrieve data. This may also result in a more efficient design. For an example, see N/cache Module Script Samples.

Returns

void

Supported Script Types

Server scripts

For additional information, see SuiteScript 2.x Script Types.

Governance

1 unit

Module

N/cache Module

Parent Object

cache.Cache

Sibling Object Members

Cache Object Members

Since

2016.2

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.key

string

required

The key corresponding to the value to be placed in the cache. This value cannot be null. For example, a ZIP code can used as the key for city names.

options.value

string

required

The value to place in the cache. If the value is not a string, the system uses JSON.stringify() to convert the value before it is placed in the cache. The maximum size of the value is 500KB.

options.ttl

number

optional

The maximum duration, in seconds, that the value may remain in the cache. Note that the value may be removed 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. Cached data is not persistent, so you should consider using the Cache.get(options) method with the options.loader parameter to set and retrieve data.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/cache Module Script Samples.

          //Add additional code 
...
var myCache = cache.getCache({
    name: 'temporaryCache',
    scope: cache.Scope.PRIVATE
});
myCache.put({
    key: 'keyText',
    value: 'valueText',
    ttl: 300
});
...
//Add additional code 

        

Related Topics

cache.Cache
N/cache Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices