Class FileDataStore (1.59.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

Google.Apis.Util.Store

Assembly

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

Folder path.

fullPathBoolean

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<T>

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