Skip to content

feat: add objectFreeze option to prevent accidental mutations of cached objects #380

@nigrosimone

Description

@nigrosimone

I would like to propose adding a new objectFreeze option to the LRUCache configuration, allowing cached objects to be frozen using Object.freeze. This would help prevent accidental mutations of cached data, increasing code safety, especially in scenarios where immutability is crucial.

import { LRUCache } from 'lru-cache'

const cache = new LRUCache({objectFreeze: process.env.NODE_ENV !== 'production'})

cache.set('key', { a: 1 })

const obj = cache.get('key');

obj.a = 2; // thrown error!!

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