# Class: Cache

Represents a cache object for storing and retrieving data using a key-value pair.

# Table of contents

# Constructors

# Properties

# Methods

# Constructors

# constructor

new Cache()

# Properties

# nodeCache

Private nodeCache: NodeCache

The NodeCache instance used to store and retrieve data.

# Defined in

src/request/request.cache.ts:27 (opens new window)


# stdTTL

Private stdTTL: number = 30

The default time-to-live (TTL) value for cached data in seconds.

# Defined in

src/request/request.cache.ts:22 (opens new window)

# Methods

# del

del(key): number

Deletes a key-value pair from the cache.

# Parameters

Name Type Description
key CacheKey The key object containing the URL, query parameters, and body of the request.

# Returns

number

True if the key-value pair was successfully deleted from the cache, false otherwise.

# Defined in

src/request/request.cache.ts:83 (opens new window)


# generateKey

Private generateKey(key): string

Generates a cache key based on the URL, query parameters, and body of a request.

# Parameters

Name Type Description
key CacheKey The key object containing the URL, query parameters, and body of the request.

# Returns

string

A unique MD5 hash key generated from the key object.

# Defined in

src/request/request.cache.ts:37 (opens new window)


# get

get(key): undefined | null | object

Retrieves a value from the cache using a given key.

# Parameters

Name Type Description
key CacheKey The key object containing the URL, query parameters, and body of the request.

# Returns

undefined | null | object

The cached value if it exists, null otherwise.

# Defined in

src/request/request.cache.ts:63 (opens new window)


# has

has(key): boolean

Checks if a key exists in the cache.

# Parameters

Name Type Description
key CacheKey The key object containing the URL, query parameters, and body of the request.

# Returns

boolean

True if the key exists in the cache, false otherwise.

# Defined in

src/request/request.cache.ts:73 (opens new window)


# set

set(key, value, ttl?): boolean

Sets a value in the cache with a given key and TTL.

# Parameters

Name Type Description
key CacheKey The key object containing the URL, query parameters, and body of the request.
value object The value to be stored in the cache.
ttl? number The TTL value for the cached data in seconds.

# Returns

boolean

True if the value was successfully stored in the cache, false otherwise.

# Defined in

src/request/request.cache.ts:49 (opens new window)