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
Google.Apis.Util.StoreAssembly
Google.Apis.dll
Constructors
FileDataStore(String, Boolean)
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 | Boolean 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<T> | 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. |