Class FileDataStore (1.60.0)

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.

Inheritance

object > FileDataStore

Implements

IDataStore

Namespace

GoogleApisUtilStore

Assembly

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
NameDescription
folderstring

Folder path.

fullPathbool

Defines whether the folder parameter is absolute or relative to Environment.SpecialFolder.ApplicationData on Windows, or$HOME on Linux and MacOS.

Properties

FolderPath

public string FolderPath { get; }

Gets the full folder path.

Property Value
TypeDescription
string

Methods

ClearAsync()

public Task ClearAsync()

Clears all values in the data store. This method deletes all files in FolderPath.

Returns
TypeDescription
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
NameDescription
keystring

The key to delete from the data store.

Returns
TypeDescription
Task
Type Parameter
NameDescription
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
NameDescription
keystring

The object key.

tType

The type to store or retrieve.

Returns
TypeDescription
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
NameDescription
keystring

The key to retrieve from the data store.

Returns
TypeDescription
Task

The stored object.

Type Parameter
NameDescription
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
NameDescription
keystring

The key.

valueT

The value to store in the data store.

Returns
TypeDescription
Task
Type Parameter
NameDescription
T

The type to store in the data store.

Extension Method