createDriverFromConfig method

  1. @override
CacheDriver createDriverFromConfig(
  1. String driverType,
  2. Map<String, dynamic> settings
)
override

Creates a cache driver instance from configuration. Throws CacheException if driver type is unknown or configuration is invalid.

Implementation

@override
CacheDriver createDriverFromConfig(
  String driverType,
  Map<String, dynamic> settings,
) {
  switch (driverType.toLowerCase()) {
    case 'memory':
      return MemoryCacheDriver();

    case 'file':
      final path = settings['path'] as String?;
      if (path == null || path.isEmpty) {
        throw CacheException('File cache driver requires a "path" setting');
      }
      return FileCacheDriver(cacheDir: path);

    case 'redis':
      final host = settings['host'] as String? ?? 'localhost';
      final port = settings['port'] as int? ?? 6379;
      final password = settings['password'] as String?;
      final database = settings['database'] as int? ?? 0;
      final maxRetries = settings['max_retries'] as int? ?? 3;
      final retryDelay = settings['retry_delay_ms'] as int? ?? 100;

      return RedisCacheDriver(
        host: host,
        port: port,
        password: password,
        database: database,
        maxRetries: maxRetries,
        retryDelay: Duration(milliseconds: retryDelay),
      );

    default:
      throw CacheException('Unknown cache driver: $driverType');
  }
}