public class FileDataStore : IDataStore
File data store that implements IDataStore. This store creates a different file for each combination of type and key. This file data store stores a JSON format of the specified object.
Implements
IDataStoreNamespace
GoogleApisUtilStoreAssembly
Google.Apis.dll
Constructors
FileDataStore(string, bool)
public FileDataStore(string folder, bool fullPath = false)
Constructs a new file data store. If fullPath
is false
the path will be used as relative to
Environment.SpecialFolder.ApplicationData"
on Windows, or $HOME
on Linux and MacOS,
otherwise the input folder will be treated as absolute.
The folder is created if it doesn't exist yet.
Parameters | |
---|---|
Name | Description |
folder |
string Folder path. |
fullPath |
bool Defines whether the folder parameter is absolute or relative to
|
Properties
FolderPath
public string FolderPath { get; }
Gets the full folder path.
Property Value | |
---|---|
Type | Description |
string |
Methods
ClearAsync()
public Task ClearAsync()
Clears all values in the data store. This method deletes all files in FolderPath.
Returns | |
---|---|
Type | Description |
Task |
DeleteAsync<T>(string)
public Task DeleteAsync<T>(string key)
Deletes the given key. It deletes the GenerateStoredKey(string, Type) named file in FolderPath.
Parameter | |
---|---|
Name | Description |
key |
string The key to delete from the data store. |
Returns | |
---|---|
Type | Description |
Task |
Type Parameter | |
---|---|
Name | Description |
T |
GenerateStoredKey(string, Type)
public static string GenerateStoredKey(string key, Type t)
Creates a unique stored key based on the key and the class type.
Parameters | |
---|---|
Name | Description |
key |
string The object key. |
t |
Type The type to store or retrieve. |
Returns | |
---|---|
Type | Description |
string |
GetAsync<T>(string)
public Task<T> GetAsync<T>(string key)
Returns the stored value for the given key or null
if the matching file (GenerateStoredKey(string, Type)
in FolderPath doesn't exist.
Parameter | |
---|---|
Name | Description |
key |
string The key to retrieve from the data store. |
Returns | |
---|---|
Type | Description |
Task |
The stored object. |
Type Parameter | |
---|---|
Name | Description |
T |
The type to retrieve. |
StoreAsync<T>(string, T)
public Task StoreAsync<T>(string key, T value)
Stores the given value for the given key. It creates a new file (named GenerateStoredKey(string, Type)) in FolderPath.
Parameters | |
---|---|
Name | Description |
key |
string The key. |
value |
T The value to store in the data store. |
Returns | |
---|---|
Type | Description |
Task |
Type Parameter | |
---|---|
Name | Description |
T |
The type to store in the data store. |