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
The SQLite Caching Library is a layer for caching data on SQLite to be used as a secondary database in case of failures and network inconsistencies.
7
8
8
-
The SQLite Caching Library is layer for caching data on SQLite to be used as a secondary database in case of failures and network inconsistences.
9
+
This library is based on `Microsoft.Extensions.Caching.StackExchangeRedis` for memory caching, but uses SQLite as the data store. It serves as a persistent cache layer, leveraging `Microsoft.Data.Sqlite`.
Visit out project at the [Nuget Repository Page](https://www.nuget.org/packages/Proxfield.Extensions.Caching.SQLite) to know more.
39
-
40
-
## How
41
-
42
-
This caching library is based on the "Microsoft.Extensions.Caching.Redis" for memory caching, but instead of using Redis it uses the SQLite as a data layer. The ideia is to be a library for persistence cache in case of failures. This library uses the "Microsoft.Data" and acts as a layer above the SQLite.
38
+
Visit the [Nuget Repository Page](https://www.nuget.org/packages/Proxfield.Extensions.Caching.SQLite) to learn more.
43
39
44
40
## Usage
45
41
46
-
The initialization can be either by using Microsoft's dependency injection or a common initialization.
42
+
Initialization can be done via standard instantiation or through Dependency Injection.
If the `options.Location` is not provided the database will be stored on the
67
-
same folder as the projet which implement the library is running.
61
+
### Configuration
62
+
63
+
#### Database File Location
64
+
65
+
If `options.Location` is not provided, the database will be stored in the same folder as the running application.
68
66
67
+
#### Encryption
69
68
70
-
### Encryption
71
-
To enable the encryption of all the data on the caching database one's just need to set the `UseEncryption` to `true` and set the `EncryptionKey` to any string, as shown bellow:
69
+
To enable data encryption, set `UseEncryption` to `true` and provide an `EncryptionKey`:
The following list constains all caching methods avaliable currently on the library.
97
-
94
+
### Available Methods
98
95
99
96
| Method | Description |
100
97
| - | - |
101
-
| byte[] Get(string key);| Retrieves a cached resource from the database |
102
-
| Task<byte[]> GetAsync(string key);| Retrieves a cached resource from the database as async|
103
-
| void Set(string key, byte[] value);| Sets a cached resource to the database |
104
-
| Task SetAsync(string key, byte[] value);| Sets a cached resource to the database async|
105
-
| void Remove(string key);| Removes a cached resource to the database |
106
-
| Task RemoveAsync(string key);| Removes a cached resource to the database as async|
107
-
| void SetAsString(string key, string value);| Sets an string into the the database |
108
-
| void SetAsObject<T>(string key, T value);| Sets an object into the the database |
109
-
| string GetAsString(string key);| Retrieves a string from the database |
110
-
| T? GetAsObject<T>(string key);| Retrieves an object from the database |
111
-
| List\<T\> GetAsObjectStartsWith<T>(this ISQLiteCache cache, string key) |Get a list of objects when the key starts with something|
112
-
| List\<string\> GetAsStringStartsWith(this ISQLiteCache cache, string key) |Get a list of strings when the key starts with something|
98
+
|`byte[] Get(string key)`| Retrieves a cached resource from the database.|
99
+
|`Task<byte[]> GetAsync(string key)`| Retrieves a cached resource asynchronously.|
100
+
|`void Set(string key, byte[] value)`| Sets a cached resource in the database.|
101
+
|`Task SetAsync(string key, byte[] value)`| Sets a cached resource asynchronously.|
102
+
|`void Remove(string key)`| Removes a cached resource from the database.|
103
+
|`Task RemoveAsync(string key)`| Removes a cached resource asynchronously.|
104
+
|`void SetAsString(string key, string value)`| Sets a string in the database.|
105
+
|`void SetAsObject<T>(string key, T value)`| Sets an object in the database.|
106
+
|`string GetAsString(string key)`| Retrieves a string from the database.|
107
+
|`T? GetAsObject<T>(string key)`| Retrieves an object from the database.|
108
+
|`List<T> GetAsObjectStartsWith<T>(this ISQLiteCache cache, string key)`|Gets a list of objects where the key starts with the specified string.|
109
+
|`List<string> GetAsStringStartsWith(this ISQLiteCache cache, string key)`|Gets a list of strings where the key starts with the specified string.|
113
110
114
111
## Collections and Indexes
115
112
116
-
It is now possible to cache objects/strings by using an index, for example, the following code on a newly created database would save the object with the key as being <strong>vehicles/1</strong>.
113
+
You can index cached objects/strings. For example, saving an object with key **vehicles/1**:
117
114
118
115
```csharp
119
-
cache.SetAsObject("vehicles|", new { Name="bycicle" });
116
+
cache.SetAsObject("vehicles/1", new { Name="bicycle" });
120
117
```
121
118
122
-
Making possible to query more than one object at once, every document on a collection.
119
+
This makes it possible to query multiple objects at once (e.g., every document in a collection):
123
120
124
121
```csharp
125
122
cache.GetAsObjectStartsWith<Vehicle>("vehicles");
126
123
```
127
124
128
-
The following list constains all indexing methods avaliable currently on the library. They can be acessed by the Maintenance property of cache (<strong>cache.Maintenance.</strong>)
125
+
### Index Management Methods
129
126
127
+
Accessed via `cache.Maintenance`.
130
128
131
129
| Method | Description |
132
130
| - | - |
133
-
| List\<SQLiteCacheIndex\> GetAllIndexes() | Returns all indexes on the database |
134
-
| SQLiteCacheIndex? GetIndex(string name | Returns an index from the database|
135
-
| void ClearAllIndexers() |Purge all indexes from the database |
136
-
| void ResetIndex(string name, long? value = null) |Reset an index to an specific value |
131
+
|`List<SQLiteCacheIndex> GetAllIndexes()`| Returns all indexes in the database.|
132
+
|`SQLiteCacheIndex? GetIndex(string name)`| Returns a specific index.|
133
+
|`void ClearAllIndexers()`|Purges all indexes from the database.|
134
+
|`void ResetIndex(string name, long? value = null)`|Resets an index to a specific value.|
137
135
138
136
## Platform Support
139
137
140
-
SQLite Caching is compiled for the following versions of frameworks:
0 commit comments