Oracle NetSuite N/cache offers coded per-feature optimization

Oracle NetSuite N/cache offers coded per-feature optimization

This appears to be a dev-specific option, not a broad/general thing like HeadInClouds’. Someone could implement this N/cache caching by writing code specific to super-slow forms, features, functions. Might be worthwhile to add onto painfully slow functions. Info, link and blurb below.

NetSuite offers the ‘N/cache’ module, which allows developers to implement caching within SuiteScript. This module can improve performance by reducing memory consumption and retrieval times for frequently accessed data. Implementing such caching solutions can significantly enhance the user experience by reducing latency and improving overall system responsiveness.​

The ‘N/cache’ module is a rarely discussed SuiteScript gem. Cache is a type of temporary storage that you can use as you create scripts. Learn with us how to use this special SuiteScript module to enhance your NetSuite coding.

NetSuite’s help documentation says the following about ‘N/cache’:

Using a cache improves performance by eliminating the need for scripts in your account to repeatedly retrieve the same piece of data.

This tool is primarily helpful on two fronts:

Using cache can reduce the memory that your script consumes when running.

Using cache can improve your script performance.

This is especially applicable when trying to handle large amounts of data. It’s difficult to dictate exactly when you should use cache, but it is an excellent option to have in cases where memory and efficiency are a concern.


The ‘N/cache’ module in NetSuite’s SuiteScript 2.0 enables developers to implement temporary, short-term data storage, enhancing performance by reducing redundant data retrievals. This module is particularly beneficial for optimizing specific features or functions that experience slow performance. Oracle Documentation

Key Features of the ‘N/cache’ Module:

  • Temporary Data Storage: Allows scripts to store data temporarily, minimizing repeated retrievals and reducing memory consumption. Oracle Documentation
  • Scoped Accessibility: Caches can be configured with different scopes—PRIVATE (accessible only to the current script), PROTECTED (accessible to all scripts in the current bundle), or PUBLIC (accessible to all scripts in the NetSuite account). Oracle Documentation
  • Customizable Time-to-Live (TTL): Developers can define how long data remains in the cache using the ‘ttl’ parameter, with a minimum of 300 seconds (5 minutes). Oracle Documentation

Implementing ‘N/cache’ in SuiteScript:

1. Retrieve or Create a Cache Object:

const cache = require('N/cache');
const myCache = cache.getCache({
    name: 'myCacheName',
    scope: cache.Scope.PUBLIC // Options: PRIVATE, PROTECTED, PUBLIC
});

2. Store Data in the Cache:

myCache.put({
    key: 'uniqueKey',
    value: 'dataToCache',
    ttl: 600 // Time-to-live in seconds
});

3. Retrieve Data from the Cache:

const cachedData = myCache.get({
    key: 'uniqueKey',
    loader: function() {
        // Function to load data if not present in cache
        return 'defaultValue';
    }
});

Considerations:

  • Volatility: Cached data is not guaranteed to persist for the entire duration of the specified TTL, as the system may clear cache entries based on resource availability. Oracle Documentation
  • Use Cases: Ideal for storing static or infrequently changing data to improve script performance and reduce execution time. SuiteRep

By leveraging the ‘N/cache’ module, developers can achieve per-feature optimization, tailoring caching strategies to specific functionalities within NetSuite. This targeted approach can lead to significant performance improvements, especially in areas with heavy data retrieval operations.

Oracle NetSuite N/cache offers coded per-feature optimization

Leave a Comment