![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@j-o-r/cache
Advanced tools
A simple cache/file write/read class, extended JSON for storing typed arrays as json
The @j-o-r/cache
package provides utilities for creating a key-value storage system that respects typed arrays. It offers both synchronous (CacheSync
) and asynchronous (CacheAsync
) versions for managing cache entries.
To use the @j-o-r/cache
package, install it via npm:
npm install @j-o-r/cache
Use CacheSync
for immediate file operations:
import { CacheSync } from '@j-o-r/cache';
const cache = new CacheSync('storage/tmp', true, 'log', 'ascii');
Use CacheAsync
for non-blocking file operations:
import { CacheAsync } from '@j-o-r/cache';
const cache = new CacheAsync('storage/tmp', true, 'log', 'ascii');
Both CacheSync
and CacheAsync
provide the following methods:
list()
: Returns an array of all keys in the cache folder.
write(key, value)
: Writes a value to the cache with the given key. If the value is not a string and the extension is not json
or ndjson
, it throws an error.
append(key, value)
: Appends a value to the cache with the given key. If the value is not a string or if JSON is used without the ndjson
extension, it throws an error.
read(key)
: Reads a value from the cache with the given key. If async, use await
. Returns undefined
if no file exists.
file(key)
: Returns a CacheFile
object with details about file path, encoding, and existence status.
delete(key)
: Deletes a file from the cache with the given key.
empty()
: Empties all files in the cache folder.
expire(time)
: Deletes files older than specified time (in milliseconds).
Synchronous Example:
const syncCache = new CacheSync('storage/tmp');
syncCache.write('key', 'value');
const syncValue = syncCache.read('key');
syncCache.delete('key');
syncCache.empty();
Asynchronous Example:
const asyncCache = new CacheAsync('storage/tmp');
await asyncCache.write('key', 'value');
const asyncValue = await asyncCache.read('key');
await asyncCache.delete('key');
await asyncCache.empty();
To enable encryption for both versions:
// For both Sync and Async:
cache.secret = 'mySecretKey';
// Write encrypted data:
cache.write('key', 'sensitive data');
// Read and decrypt data:
let decryptedValue;
if (cache instanceof CacheSync) {
decryptedValue = cache.read('key'); // Synchronous read
} else {
decryptedValue = await cache.read('key'); // Asynchronous read with await
}
console.log(decryptedValue); // Outputs: 'sensitive data'
This project is licensed under APACHE 2.0 License. See LICENSE file for details.
FAQs
A simple cache/file write/read class, extended JSON for storing typed arrays as json
The npm package @j-o-r/cache receives a total of 6 weekly downloads. As such, @j-o-r/cache popularity was classified as not popular.
We found that @j-o-r/cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.