update tsconfig
This commit is contained in:
parent
57c2e33a6c
commit
abfa1e1c70
@ -9,12 +9,24 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartcache",
|
"gitrepo": "smartcache",
|
||||||
"description": "cache things in smart ways",
|
"description": "A module for caching asynchronous function results with smart time and hash-based invalidation strategies.",
|
||||||
"npmPackagename": "@push.rocks/smartcache",
|
"npmPackagename": "@push.rocks/smartcache",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"caching",
|
||||||
|
"asynchronous",
|
||||||
|
"time-based invalidation",
|
||||||
|
"hash-based identification",
|
||||||
|
"smart caching",
|
||||||
|
"node.js",
|
||||||
|
"performance optimization",
|
||||||
|
"typescript",
|
||||||
|
"delay handling",
|
||||||
|
"error management"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tsdocs": {
|
"tsdoc": {
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
16
package.json
16
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@push.rocks/smartcache",
|
"name": "@push.rocks/smartcache",
|
||||||
"version": "1.0.16",
|
"version": "1.0.16",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "cache things in smart ways",
|
"description": "A module for caching asynchronous function results with smart time and hash-based invalidation strategies.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
@ -41,5 +41,17 @@
|
|||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
],
|
],
|
||||||
"type": "module"
|
"type": "module",
|
||||||
|
"keywords": [
|
||||||
|
"caching",
|
||||||
|
"asynchronous",
|
||||||
|
"time-based invalidation",
|
||||||
|
"hash-based identification",
|
||||||
|
"smart caching",
|
||||||
|
"node.js",
|
||||||
|
"performance optimization",
|
||||||
|
"typescript",
|
||||||
|
"delay handling",
|
||||||
|
"error management"
|
||||||
|
]
|
||||||
}
|
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
130
readme.md
130
readme.md
@ -1,41 +1,113 @@
|
|||||||
# @pushrocks/smartcache
|
# @push.rocks/smartcache
|
||||||
cache things in smart ways
|
Cache things in smart ways.
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartcache)
|
To use `@push.rocks/smartcache` in your project, you'll need to install it using npm or yarn. Here's how you can do it:
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartcache)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartcache)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcache/)
|
|
||||||
|
|
||||||
## Status for master
|
```bash
|
||||||
|
npm install @push.rocks/smartcache --save
|
||||||
|
```
|
||||||
|
or if you are using yarn:
|
||||||
|
|
||||||
Status Category | Status Badge
|
```bash
|
||||||
-- | --
|
yarn add @push.rocks/smartcache
|
||||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartcache/badges/master/pipeline.svg)](https://lossless.cloud)
|
```
|
||||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartcache/badges/master/coverage.svg)](https://lossless.cloud)
|
|
||||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartcache)](https://lossless.cloud)
|
|
||||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartcache)](https://lossless.cloud)
|
|
||||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
|
||||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartcache)](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartcache)](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartcache)](https://lossless.cloud)
|
|
||||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
## Contribution
|
`@push.rocks/smartcache` is designed to cache the results of function calls in a smart and efficient way, significantly improving the performance of repeat function calls by avoiding unnecessary recalculations or remote fetches. This package is especially useful when dealing with data that changes infrequently or expensive computation functions whose results can be reused within a given period. Here's how to use `@push.rocks/smartcache` in your TypeScript projects:
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
First, make sure to import `SmartCache`:
|
||||||
|
|
||||||
## Contribution
|
```typescript
|
||||||
|
import { SmartCache } from '@push.rocks/smartcache';
|
||||||
|
```
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
### Basic Example
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
Create an instance of `SmartCache`:
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
```typescript
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
const mySmartCache = new SmartCache();
|
||||||
|
```
|
||||||
|
|
||||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
Now, imagine you have an asynchronous function whose result you want to cache:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function fetchData(): Promise<string> {
|
||||||
|
// simulate fetching data
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000)); // delay to mimic fetch time
|
||||||
|
return 'Some fetched data';
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Using `@push.rocks/smartcache`, you can cache the result of `fetchData` easily:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function getCachedData() {
|
||||||
|
const cachedData = await mySmartCache.cacheReturn(fetchData, 60000); // Cache for 1 minute
|
||||||
|
console.log(cachedData); // 'Some fetched data'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Use Cases
|
||||||
|
|
||||||
|
#### Custom Cache Identifiers
|
||||||
|
|
||||||
|
By default, `@push.rocks/smartcache` identifies cache entries based on the call stack. However, when you have dynamic arguments that significantly change the output of the function, you might want to create a custom cache identifier to differentiate between these calls.
|
||||||
|
|
||||||
|
Suppose `fetchData` now takes an argument:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function fetchData(userId: string): Promise<UserData> {
|
||||||
|
// Fetch user data based on userId
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You could create a custom cache identifier like so:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const userId = '123';
|
||||||
|
const customIdentifier = `fetchData-${userId}`;
|
||||||
|
|
||||||
|
const cachedUserData = await mySmartCache.cacheReturn(() => fetchData(userId), 60000, customIdentifier);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Clearing the Cache
|
||||||
|
|
||||||
|
In certain situations, you might want to clear the cached data before it expires naturally. `@push.rocks/smartcache` provides a method to manually clear specific cache entries:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
mySmartCache.clearCache(customIdentifier);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Best Practices
|
||||||
|
|
||||||
|
- **Cache Duration**: Choose a cache duration that makes sense for your data. Highly dynamic data might not benefit much from long cache times, whereas static data can be cached longer.
|
||||||
|
- **Error Handling**: Always implement error handling for your cached functions, especially when dealing with network requests.
|
||||||
|
- **Memory Management**: Be mindful of what you cache. Caching large objects or a high number of entries can lead to increased memory usage.
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
`@push.rocks/smartcache` is a powerful utility for caching asynchronous function results, significantly improving the performance and efficiency of your applications. By understanding and implementing the basics and exploring advanced use cases, you can leverage `@push.rocks/smartcache` to its full potential.
|
||||||
|
|
||||||
|
Remember, the key to effective caching is understanding your data's behavior and aligning your caching strategy accordingly. Happy caching!
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
Loading…
Reference in New Issue
Block a user