You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a wrapper on top of [Blazored.LocalStorage](https://github.com/Blazored/LocalStorage) and [Blazored.SessionStorage](https://github.com/Blazored/SessionStorage) to expire items from localstorage and sessionstorage after a specified time.
5
4
6
-
Blazored is archived, I will build my own implementation.
5
+
Store api responses in localstorage and sessionstorage.
6
+
7
+
Configure if the api should be called or the cached value will be returned if available.
7
8
8
9
## Installing
9
10
10
-
To install the package add the following line to you csproj file replacing x.x.x with the latest version number (found at the top of this file):
11
+
To install the package, add the following line to the csproj file. Replacing x.x.x with the latest version number (found at the top of this file):
@@ -32,7 +33,7 @@ public void ConfigureServices(IServiceCollection services)
32
33
}
33
34
```
34
35
35
-
Or in your _Program.cs_ file in Blazor WebAssembly.
36
+
Or in your *Program.cs* file in Blazor WebAssembly.
36
37
37
38
```c#
38
39
publicstaticasyncTaskMain(string[] args)
@@ -46,8 +47,6 @@ public static async Task Main(string[] args)
46
47
}
47
48
```
48
49
49
-
If you use Blazored.LocalStorage or Blazored.SessionStorage with configuration those will need to be registered before Drogecode.Blazor.ExpireStorage.
50
-
51
50
## Usage (Blazor WebAssembly)
52
51
example
53
52
@@ -75,27 +74,35 @@ example
75
74
### CachedRequest
76
75
You can give optional settings to the CachedRequest object.
77
76
78
-
***OneCallPerSession** - If true, the result will be returned from sessionstorage if it is not expired. *Default: false*
79
77
***OneCallPerLocalStorage** - If true, the result will be returned from localstorage if it is not expired. *Default: false*
78
+
***OneCallPerSession** - If true, the result will be returned from sessionstorage if it is not expired. *Default: false*
79
+
***ExpireLocalStorage** - The DateTime the localstorage value will be expired. *Default: 7 days.*
80
+
***ExpireSessionStorage** - The DateTime the sessionstorage value will be expired. *Default: 15 minutes.*
80
81
***IgnoreCache** - If true, never return a cached result. *Default: false*
81
-
***ExpireLocalStorage** - The time to expire the result in localstorage. *Default: 7 days.*
82
-
***ExpireSessionStorage** - The time to expire the result in sessionstorage. *Default: 15 minutes.*
83
82
***CachedAndReplace** - If true, The cached result will be returned and the cache will be refreshed for the next call. *Default: false*
84
-
***AlwaysCacheWhenOffline** - If true, the cached result will be returned when offline, except when IgnoreCache is true. *Default: false*
85
-
***RetryOnJsonException** - If true, If a JSON exception occurs, the cache will be cleared and the request will be retried. *Default: true*
83
+
***CacheWhenOffline** - If true, the cached result will be returned when offline, except when IgnoreCache is true. *Default: false*
84
+
***RetryOnJsonException** - If true, If a JSON exception occurs, the cache will be cleared and the request will be retried once. This will minimize the effect if a breaking change was introduced in the JSON value. *Default: true*
86
85
87
86
### Global settings
88
87
88
+
#### Postfix
89
89
On, for example, MainLayout.razor.cs, you can set the Postfix to be used for all requests. This is useful if you have multiple users using the same app from the same browser.
ExpireStorageService knows two properties to monitor if the app is offline.
94
95
95
-
IsOffline is true when the last request had an `HttpRequestException`.
96
+
IsOffline is true when the last request had an `HttpRequestException`, after a successful request IsOffline will be false.
96
97
97
98
`ExpireStorageService.IsOffline` and `ExpireStorageService.IsOfflineChanged`
98
99
100
+
#### LogToConsole
101
+
102
+
ExpireStorageService can log to the console if you want to see what is happening, *default: false*.
103
+
104
+
`ExpireStorageService.LogToConsole = true;`
105
+
99
106
### ICacheableResponse
100
107
101
108
If a response object implements ICacheableResponse, the HandledBy property will be set to `HandledBy.Cache` if the result was retrieved from cache and to `HandledBy.Default` if the default provided by the caller was used.
@@ -109,3 +116,13 @@ public class YourObjectResponse : ICacheableResponse
109
116
...
110
117
}
111
118
```
119
+
120
+
## Cache
121
+
122
+
The cache is stored as a base64 string and serialized / deserialized using System.Text.Json.
123
+
124
+
### Cleanup
125
+
126
+
One minute after the app starts, the local storage cache will be cleared from all expired values.
127
+
128
+
Items that are expired but not yet deleted will not be returned.
0 commit comments