DatabaseConnectionCache

Ecng.Data

Represents a cache for DatabaseConnectionPair objects.

Реализует: IAsyncPersistable

Свойства

Connections
public IEnumerable<DatabaseConnectionPair> Connections { get; }
value = databaseConnectionCache.Connections

Gets all database connection pairs.

Методы

DeleteConnection
public bool DeleteConnection(DatabaseConnectionPair connection)
result = databaseConnectionCache.DeleteConnection(connection)

Deletes the specified database connection pair from the cache.

connection
The database connection pair to delete.

Возвращает: True if the connection was successfully removed; otherwise, false.

GetOrAdd
public DatabaseConnectionPair GetOrAdd(string provider, string connectionString)
result = databaseConnectionCache.GetOrAdd(provider, connectionString)

Retrieves an existing connection matching the specified provider and connection string or adds a new connection if it does not exist.

provider
The database provider.
connectionString
The connection string.

Возвращает: The corresponding DatabaseConnectionPair.

LoadAsync
public Task LoadAsync(SettingsStorage storage, CancellationToken cancellationToken)
result = databaseConnectionCache.LoadAsync(storage, cancellationToken)

Loads the database connection pairs from the specified settings storage.

storage
The settings storage to load from.
cancellationToken
CancellationToken

Возвращает: Task

SaveAsync
public Task SaveAsync(SettingsStorage storage, CancellationToken cancellationToken)
result = databaseConnectionCache.SaveAsync(storage, cancellationToken)

Saves the database connection pairs to the specified settings storage.

storage
The settings storage to save to.
cancellationToken
CancellationToken

Возвращает: Task

События

ConnectionCreated
public event Action<DatabaseConnectionPair> ConnectionCreated
databaseConnectionCache.ConnectionCreated += handler

Occurs when a new database connection pair is created.

ConnectionDeleted
public event Action<DatabaseConnectionPair> ConnectionDeleted
databaseConnectionCache.ConnectionDeleted += handler

Occurs when a database connection pair is deleted.

Updated
public event Action Updated
databaseConnectionCache.Updated += handler

Occurs when the connection cache is updated.