Set CDN Cache Duration in SuiteScript for Enhanced Performance

Set CDN caching duration in SuiteScript to optimize response times. Enhance Suitelet performance with caching options.

·2 min read·View Oracle Docs

TL;DR Opening

Setting the CDN cache duration in SuiteScript allows developers to control how long content is cached. This enhances performance, especially for Suitelets, by reducing the need for repetitive processing and improving load times.

What is CDN Caching?

CDN (Content Delivery Network) caching is a technique that allows frequently accessed content to be stored temporarily to minimize server load and improve response times for users. By setting an appropriate caching duration, developers can ensure that cached responses are delivered quickly without unnecessary delays.

Method Description

The setCdnCacheable method is used to specify CDN caching for a designated time period. It can be invoked within server scripts, enhancing Suitelet performance by reducing the load on server resources when the same content is repeatedly requested.

Returns

  • Returns void

Supported Script Types

  • This method is applicable for server scripts.

Governance

  • There are no governance limits associated with this method.

Module

  • N/http Module

Parent Object

  • This method belongs to the http.ServerResponse object.

Parameters

The method accepts an options parameter, which is a JavaScript object that determines the caching behavior. The following table outlines the parameters:

ParameterTypeRequired / OptionalDescription
options.typeenumrequiredSets the value of caching duration. Using http.CacheDuration, you can configure this value. If UNIQUE is specified with a Suitelet, the Suitelet will not be cached, ensuring it always processes fresh requests.

Error Handling

When using this method, developers should be aware of potential error codes:

  • Error Code: SSS_MISSING_REQD_ARGUMENT
    • Message: Missing a required argument: {param name}
    • Thrown If: The options.type parameter is not specified.

Syntax Example

This code snippet demonstrates how to use the setCdnCacheable method within your script:

suitescript
// Example SuiteScript code
serverResponse.setCdnCacheable({
type: http.CacheDuration.MAX
});

This example sets the caching duration to the maximum allowed, optimizing the Suitelet responses.

Related Topics

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The setCdnCacheable method enables dynamic CDN caching management.
  • Use it to enhance Suitelet performance by avoiding redundant processing.
  • Developers must specify the options.type to avoid errors related to missing parameters.

Frequently Asked Questions (4)

Is the setCdnCacheable method applicable to all script types in NetSuite?
No, the setCdnCacheable method is applicable only for server scripts.
Are there any governance limits associated with using the setCdnCacheable method?
There are no governance limits associated with the setCdnCacheable method.
What happens if the options.type parameter is not specified when using setCdnCacheable?
If the options.type parameter is not specified, an error will be thrown with the error code SSS_MISSING_REQD_ARGUMENT, indicating a missing required argument.
What is the role of the options parameter in the setCdnCacheable method?
The options parameter is a JavaScript object that determines caching behavior. It requires specifying the options.type, which configures caching duration using http.CacheDuration.
Source: Parameters Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in SuiteScript

View all SuiteScript articles →