Cache Object Members in SuiteScript with N/cache Module
Cache Object Members in SuiteScript facilitate temporary data storage with the N/cache module, enhancing script performance.
TL;DR
The Cache Object Members in SuiteScript utilize the N/cache module to enable temporary storage of data, improving script performance by reducing redundant data retrievals. Caches can have specified availability and expiration times, making them an efficient tool for developers.
How Does the N/cache Module Work?
The N/cache module is used for temporary data storage, allowing scripts to cache values and avoid repeated fetching of the same data. This approach can significantly enhance the performance of server scripts by storing frequently used information in a cache that is accessible by keys.
Cache Availability
When creating a cache with the N/cache module, developers can define its scope:
- Current Script Only: Accessible only within the script where it is created.
- Current Bundle: Available to all server scripts contained within the current bundle.
- Entire Account: Usable across all server scripts in your NetSuite account.
Data in the cache has a time-to-live (ttl) value, which specifies how long the data remains in the cache before it is eligible for removal. This management helps keep cache size in check and can prevent stale data from lingering.
Cache Object Members
The following table details the cache object members available through the N/cache module:
| Member Type | Name | Return Type / Value Type | Supported Script Types | Description |
|---|---|---|---|---|
| Method | [Cache.get(options)] | string | Server scripts | Retrieves a value from the cache based on a specified key. If it's not present, it can invoke a user-defined loading function. |
| Method | [Cache.put(options)] | string | Server scripts | Stores a value in the cache; if the value is not a string, it's converted using JSON.stringify(). |
| Method | [Cache.remove(options)] | string | Server scripts | Removes a specific value from the cache. |
| Property | [Cache.name] | string | Server scripts | The assigned name of the cache for identification. |
| Property | [Cache.scope] | string | Server scripts | Indicates the cache availability (current script, bundle, or account). |
Cache operations are straightforward and are designed to streamline data retrieval, enhancing overall performance in NetSuite scripting.
Best Practices for Using Cache
- Use caching for frequently accessed data that doesn't change often.
- Regularly review cache entries and set appropriate time-to-live values to avoid using outdated data.
- Consider the scope of your cache; limit it to the appropriate level to reduce memory consumption.
Who This Affects
- Developers: Those creating server-side scripts can benefit significantly from using cache to improve execution speed.
- Administrators: Understanding how cache works can help in managing performance across scripts.
Key Takeaways
- The N/cache module allows for efficient temporary data storage.
- Caches can be scoped to different levels of script access.
- Proper management of cache time-to-live (ttl) is essential.
- Retrieving and storing data in the cache can significantly enhance script performance.
Frequently Asked Questions (4)
What scope options are available for caches created using the N/cache module in SuiteScript?
How long can data remain in a cache created with the N/cache module before it is removed?
What happens if I try to cache a non-string value with the N/cache module?
Can I use the N/cache module methods in client scripts?
Was this article helpful?
More in Performance
- Non-Production Account Access with Account Warmer SuiteApp 2026.1
The Account Warmer SuiteApp for NetSuite 2026.1 optimizes access in non-production environments, significantly reducing load times.
- SCEM Automatic JavaScript Code Optimization in NetSuite 2026.1
SCEM introduces automatic JavaScript code optimization for better performance and security in NetSuite 2026.1.
- NetSuite Usage Optimization: Avoid Excessive Service Cons...
Optimize NetSuite usage by avoiding excessive consumption of resources to maintain peak performance in a multi-tenant environment.
- Home Page Performance Optimization in SuiteCommerce
Optimize slow home page loading times in SuiteCommerce using diagnostics and resource tracking methods.
Advertising
Reach Performance Professionals
Put your product in front of NetSuite experts who work with Performance every day.
Sponsor This Category