Node.js의 script.createCachedData() 메소드

王林
풀어 주다: 2023-09-04 21:21:08
앞으로
1176명이 탐색했습니다.

Node.js 中的 script.createCachedData() 方法

script.createCachedData() 메서드는 스크립트 생성자의 캐시된 데이터 옵션과 함께 사용할 코드 캐시를 만드는 데 사용됩니다. 이 캐시된 데이터는 지연 없이 여러 번 호출될 수 있습니다. 이 방법은 스크립트 모듈의 내장 프로그래밍 인터페이스입니다.

Syntax

script.createCachedData()
로그인 후 복사

Parameters

왜냐하면 데이터만 캐시하기 때문입니다. 사용자의 특정 입력이 필요하지 않습니다. 캐시된 버퍼만 반환합니다.

Example

createCachedData.js라는 파일을 만들고 다음 코드 조각을 복사하세요. 파일을 생성한 후 아래 예제와 같이 다음 명령을 사용하여 이 코드를 실행합니다. -

node createCachedData.js
로그인 후 복사

createCachedData.js

// Node.js program to demonstrate the flow of script.createCachedData() method

// Importing the vm module
const vm = require("vm");

// Defining the script as constant and usng the below function
// to create the cached data for the difference of two numbers.
const script = new vm.Script(`
   function add(a, b) {
      return a - b;
   }
   const x = add(2, 1);
`);

//Creating the cached data without caching the variable
const cacheWithoutx = script.createCachedData();
console.log(cacheWithoutx);
로그인 후 복사

Output

C:\homeode>> node createCachedData.js
<Buffer b5 03 de c0 8a f4 d4 f4 3d 00 00 00 ff 03 00 00 d5 a2 f5 b7 06 00 00
00 00 00 00 00 28 02 00 00 8f 87 4d e3 59 55 98 f9 00 00 00 80 20 00 00 80 00
03 ... >
로그인 후 복사

Example

예제를 하나 더 살펴보겠습니다.

// Node.js program to demonstrate the flow of script.createCachedData() method

// Importing the vm module
const vm = require("vm");

// Defining the script as constant and usng the below function
// to create the cached data for the difference of two numbers.
const script = new vm.Script(`
   function add(a, b) {
      return a - b;
   }
   const x = add(2, 1);
`);

// Calling the runInThisContext from script module
script.runInThisContext();

//Creating the cached data along with caching the variable
const cacheWithx = script.createCachedData();
console.log(cacheWithx);
로그인 후 복사

출력

C:\homeode>> node createCachedData.js
<Buffer b5 03 de c0 8a f4 d4 f4 3d 00 00 00 ff 03 00 00 d5 a2 f5 b7 06 00 00
00 00 00 00 00 00 03 00 00 15 80 fd 5d 69 21 3a a9 00 00 00 80 20 00 00 80 38
04 ... >
로그인 후 복사

위 내용은 Node.js의 script.createCachedData() 메소드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!