Skip to content

Clarify ttl Parameter in CacheInstance.set Method with Better Naming and JSDoc #87

@Ealenn

Description

@Ealenn

In the CacheInstance interface, the set method includes a ttl parameter. However, the current naming and lack of JSDoc documentation make it unclear whether the ttl value is interpreted in seconds or milliseconds. This ambiguity can lead to confusion for developers using the library, potentially causing incorrect cache expiration behavior.

Proposed Solutions

1 Rename the ttl parameter to a more descriptive name that explicitly indicates the unit of time.

Suggested options:

  • ttlInSeconds / ttlMs
  • expiresAfterMs / expiresAfterSecond
  • lifespanSeconds / lifespanMs

2 Add JSDoc documentation to clearly specify the unit of time and provide details about the parameter's purpose.

Assuming the ttl is in milliseconds (please confirm the intended unit), the updated interface could look like this:

interface CacheInstance {
  /**
   * Sets a key-value pair in the cache with a specified expiration time.
   * @param key - The cache key.
   * @param value - The value to cache.
   * @param ttl - The time-to-live for the cache entry, in milliseconds.
   */
  set(key: string, value: any, ttl: number): void;
}

I might suggest a PR for at least add the JSDoc, please confirm that it's in miliseconds <3

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions