Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Possibility to configure quota with node-localstorage? #38

@fabiancook

Description

@fabiancook

I have received this here on a project I have been working on:

QUOTA_EXCEEDED_ERR: Unknown error.
    at LocalStorage.setItem (/node_modules/node-localstorage/LocalStorage.js:215:15)
    at setItem (/node_modules/@kvs/storage/src/storage.ts:34:20)
    at <anonymous> (/node_modules/@kvs/storage/src/storage.ts:156:35)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at run (/some-file.ts:97:17)

It would be good if we could pass something or the same default as a second argument here

storage: new LocalStorage(saveFilePath)

Looking at the node-localstorage implementation here:

https://github.com/lmaccherone/node-localstorage/blob/5498cdbd2e26819351eb505e71aae1feafdad81b/LocalStorage.coffee#L53

https://github.com/lmaccherone/node-localstorage/blob/5498cdbd2e26819351eb505e71aae1feafdad81b/LocalStorage.coffee#L145-L146

5 * 1024 * 1024 is the default value

I did just change the value up to 25 * 1024 * 1024 right in the dependency code for now, but I should probably do a PR for it instead.

Say something like...

export type KvsLocalStorageOptions<Schema extends KvsLocalStorageSchema> = KVSOptions<Schema> & {
    kvsVersionKey?: string;
    storeFilePath?: string;
    storeQuota?: number;
};
export const kvsLocalStorage = async <Schema extends KvsLocalStorageSchema>(
    options: KvsLocalStorageOptions<Schema>
): Promise<KvsStorage<Schema>> => {
    const defaultCacheDir = path.join(appRoot.toString(), ".cache");
    if (!options.storeFilePath) {
        await mkdirp(defaultCacheDir);
    }
    const saveFilePath = options.storeFilePath
        ? options.storeFilePath
        : path.join(defaultCacheDir, "kvs-node-localstorage");
    const storeQuota = options.storeQuota 
        ? options.storeQuota
        : 5 * 1024 * 1024
    return kvsStorage({
        ...options,
        storage: new LocalStorage(saveFilePath, storeQuota)
    });
};

How does this then work with @kvs/env ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions