ngx-api-cache 20.0.1 → 20.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +71 -15
- package/package.json +7 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sokolov Andrey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ This project was generated using [Angular CLI](https://github.com/angular/angula
|
|
|
4
4
|
|
|
5
5
|
## Description
|
|
6
6
|
|
|
7
|
-
This is a very lightweight library for
|
|
7
|
+
This is a very lightweight library for api-cache.
|
|
8
8
|
|
|
9
9
|
This library does not require third party dependencies
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ This library does not require third party dependencies
|
|
|
13
13
|
1. Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm i ngx-api-cache
|
|
16
|
+
npm i ngx-api-cache
|
|
17
17
|
```
|
|
18
18
|
OR
|
|
19
19
|
|
|
@@ -21,24 +21,80 @@ This library does not require third party dependencies
|
|
|
21
21
|
yarn add ngx-api-cache
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
2.
|
|
24
|
+
2. Provide HttpClient to your App:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
|
|
27
|
+
import { provideHttpClient } from '@angular/common/http';
|
|
28
|
+
|
|
29
|
+
// In your app config:
|
|
30
|
+
providers: [
|
|
31
|
+
provideHttpClient(), // ← required
|
|
32
|
+
// ... other providers
|
|
33
|
+
]
|
|
28
34
|
```
|
|
29
35
|
|
|
30
|
-
3.
|
|
36
|
+
3. Inject NgxApiCacheService in any standalone component or service:
|
|
31
37
|
|
|
32
38
|
```bash
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
|
|
40
|
+
const apiCache = inject(NgxApiCacheService);
|
|
41
|
+
const result: CacheResult<User> = apiCache.get('/api/user');
|
|
42
|
+
if you want, you can also add destroyRef: apiCache.get('/api/user', destroyRef);
|
|
43
|
+
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
The returned result object gives you:
|
|
46
|
+
data: a readonly signal with the response (or null)
|
|
47
|
+
loading: a readonly signal indicating if a request is in progress
|
|
48
|
+
error: a readonly signal with the error (or null)
|
|
49
|
+
refresh(): re-fetches data from the API (bypassing cache)
|
|
50
|
+
patch(updater): lets you update the cached value directly (e.g., for optimistic UI)
|
|
43
51
|
```
|
|
44
|
-
|
|
52
|
+
4. Example for template:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
@if (result.loading(); as loading) {
|
|
56
|
+
<p>Loading... {{ loading }}</p>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@if (result.error(); as error) {
|
|
60
|
+
<div class="error">
|
|
61
|
+
<p>Failed to load data.</p>
|
|
62
|
+
<button (click)="result.refresh()">Retry</button>
|
|
63
|
+
</div>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@if (result.data(); as data) {
|
|
67
|
+
<div class="content">
|
|
68
|
+
<h2>{{ data.name }}</h2>
|
|
69
|
+
<p>{{ data.position }}</p>
|
|
70
|
+
<button (click)="result.refresh()">Refresh</button>
|
|
71
|
+
</div>
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
5. Example for patch method:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
// 1) Edit. After user edits their name in a form:
|
|
79
|
+
userResult.patch(user => ({
|
|
80
|
+
...user,
|
|
81
|
+
name: 'Alex Updated'
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
// 2) Delete. In your component:
|
|
85
|
+
deleteTodo(id: number) {
|
|
86
|
+
todosResult.patch(todos => todos.filter(todo => todo.id !== id));
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Keywords
|
|
91
|
+
angular, api, cache
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## 💸 Support project
|
|
95
|
+
|
|
96
|
+
[](https://andrew-dev283.github.io/andrew-dev.github.io/)
|
|
97
|
+
|
|
98
|
+
OR
|
|
99
|
+
|
|
100
|
+
https://boosty.to/hq_dev
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-api-cache",
|
|
3
|
-
"version": "20.0.
|
|
3
|
+
"version": "20.0.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^20.3.1",
|
|
6
6
|
"@angular/core": "^20.3.1"
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
}
|
|
21
21
|
],
|
|
22
22
|
"homepage": "https://github.com/andrew-dev283/ngx-api-cache",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"angular",
|
|
26
|
+
"api",
|
|
27
|
+
"cache"
|
|
28
|
+
],
|
|
23
29
|
"repository": {
|
|
24
30
|
"type": "git",
|
|
25
31
|
"url": "https://github.com/andrew-dev283/ngx-api-cache.git"
|