Skip to content

Commit b718b95

Browse files
committed
refactor: add Driver suffix to all drivers
1 parent 58d4879 commit b718b95

14 files changed

+52
-52
lines changed

packages/bentocache/factories/cache_factory.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import lodash from '@poppinss/utils/lodash'
22
import { getActiveTest } from '@japa/runner'
33

44
import { Cache } from '../src/cache/cache.js'
5-
import { Redis } from '../src/drivers/redis.js'
6-
import { Memory } from '../src/drivers/memory.js'
5+
import { RedisDriver } from '../src/drivers/redis.js'
6+
import { MemoryDriver } from '../src/drivers/memory.js'
77
import { MemoryBus } from '../src/bus/drivers/memory_bus.js'
88
import type { CacheStackDrivers } from '../src/types/main.js'
99
import { CacheStack } from '../src/cache/stack/cache_stack.js'
@@ -62,24 +62,24 @@ export class CacheFactory {
6262
* Adds a Memory L1 driver to the cache stack
6363
*/
6464
withMemoryL1() {
65-
this.#parameters.l1Driver = new Memory({ maxSize: 100, prefix: 'test' })
65+
this.#parameters.l1Driver = new MemoryDriver({ maxSize: 100, prefix: 'test' })
6666
return this
6767
}
6868

6969
/**
7070
* Adds a Redis L2 driver to the cache stack
7171
*/
7272
withRedisL2() {
73-
this.#parameters.l2Driver = new Redis({ connection: { host: '127.0.0.1', port: 6379 } })
73+
this.#parameters.l2Driver = new RedisDriver({ connection: { host: '127.0.0.1', port: 6379 } })
7474
return this
7575
}
7676

7777
/**
7878
* Adds a cache stack preset with Memory + Redis + Memory Bus
7979
*/
8080
withL1L2Config() {
81-
this.#parameters.l1Driver ??= new Memory({ maxSize: 100, prefix: 'test' })
82-
this.#parameters.l2Driver ??= new Redis({ connection: { host: '127.0.0.1', port: 6379 } })
81+
this.#parameters.l1Driver ??= new MemoryDriver({ maxSize: 100, prefix: 'test' })
82+
this.#parameters.l2Driver ??= new RedisDriver({ connection: { host: '127.0.0.1', port: 6379 } })
8383
this.#parameters.busDriver ??= new MemoryBus()
8484

8585
return this

packages/bentocache/src/drivers/dynamodb.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ import type { CacheDriver, CreateDriverResult, DynamoDBConfig } from '../types/m
1616
/**
1717
* Create a new DynamoDB driver
1818
*/
19-
export function dynamoDbDriver(options: DynamoDBConfig): CreateDriverResult<DynamoDB> {
19+
export function dynamoDbDriver(options: DynamoDBConfig): CreateDriverResult<DynamoDbDriver> {
2020
return {
2121
options,
22-
factory: (config: DynamoDBConfig) => new DynamoDB(config),
22+
factory: (config: DynamoDBConfig) => new DynamoDbDriver(config),
2323
}
2424
}
2525

2626
/**
2727
* Caching driver for DynamoDB
2828
*/
29-
export class DynamoDB extends BaseDriver implements CacheDriver {
29+
export class DynamoDbDriver extends BaseDriver implements CacheDriver {
3030
type = 'l2' as const
3131

3232
/**
@@ -144,7 +144,7 @@ export class DynamoDB extends BaseDriver implements CacheDriver {
144144
* Returns a new instance of the driver with the given namespace.
145145
*/
146146
namespace(namespace: string) {
147-
return new DynamoDB({
147+
return new DynamoDbDriver({
148148
...this.config,
149149
client: this.#client,
150150
prefix: this.createNamespacePrefix(namespace),

packages/bentocache/src/drivers/file.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type { CacheDriver, CreateDriverResult, FileConfig } from '../types/main.
77
/**
88
* Create a new file driver
99
*/
10-
export function fileDriver(options: FileConfig): CreateDriverResult<File> {
10+
export function fileDriver(options: FileConfig): CreateDriverResult<FileDriver> {
1111
return {
1212
options,
13-
factory: (config: FileConfig) => new File(config),
13+
factory: (config: FileConfig) => new FileDriver(config),
1414
}
1515
}
1616

@@ -22,7 +22,7 @@ export function fileDriver(options: FileConfig): CreateDriverResult<File> {
2222
* - Files are stored in the following format: [stringifiedValue, expireTimestamp]
2323
* - If the expireTimestamp is -1, the value should never expire
2424
*/
25-
export class File extends BaseDriver implements CacheDriver {
25+
export class FileDriver extends BaseDriver implements CacheDriver {
2626
type = 'l2' as const
2727

2828
/**
@@ -95,7 +95,7 @@ export class File extends BaseDriver implements CacheDriver {
9595
* Returns a new instance of the driver namespaced
9696
*/
9797
namespace(namespace: string) {
98-
return new File({
98+
return new FileDriver({
9999
...this.config,
100100
prefix: this.createNamespacePrefix(namespace),
101101
})

packages/bentocache/src/drivers/memory.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import type {
1010
/**
1111
* Create a new memory driver
1212
*/
13-
export function memoryDriver(options: MemoryConfig = {}): CreateDriverResult<Memory> {
13+
export function memoryDriver(options: MemoryConfig = {}): CreateDriverResult<MemoryDriver> {
1414
return {
1515
options,
16-
factory: (config: MemoryConfig) => new Memory(config),
16+
factory: (config: MemoryConfig) => new MemoryDriver(config),
1717
}
1818
}
1919

2020
/**
2121
* A memory caching driver
2222
*/
23-
export class Memory extends BaseDriver implements L1CacheDriver {
23+
export class MemoryDriver extends BaseDriver implements L1CacheDriver {
2424
type = 'l1' as const
2525
#cache: LRUCache<string, string>
2626
declare config: MemoryConfig
@@ -50,7 +50,7 @@ export class Memory extends BaseDriver implements L1CacheDriver {
5050
* Returns a new instance of the driver namespaced
5151
*/
5252
namespace(namespace: string) {
53-
return new Memory({
53+
return new MemoryDriver({
5454
...this.config,
5555
cacheInstance: this.#cache,
5656
prefix: this.createNamespacePrefix(namespace),

packages/bentocache/src/drivers/redis.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {
1414
/**
1515
* Create a new cache redis driver
1616
*/
17-
export function redisDriver(options: RedisConfig): CreateDriverResult<Redis> {
18-
return { options, factory: (config: RedisConfig) => new Redis(config) }
17+
export function redisDriver(options: RedisConfig): CreateDriverResult<RedisDriver> {
18+
return { options, factory: (config: RedisConfig) => new RedisDriver(config) }
1919
}
2020

2121
/**
@@ -31,7 +31,7 @@ export function redisBusDriver(
3131
/**
3232
* Caching driver for Redis
3333
*/
34-
export class Redis extends BaseDriver implements L2CacheDriver {
34+
export class RedisDriver extends BaseDriver implements L2CacheDriver {
3535
type = 'l2' as const
3636
#connection: IoRedis
3737
declare config: RedisConfig
@@ -55,7 +55,7 @@ export class Redis extends BaseDriver implements L2CacheDriver {
5555
* Returns a new instance of the driver namespaced
5656
*/
5757
namespace(namespace: string) {
58-
return new Redis({
58+
return new RedisDriver({
5959
...this.config,
6060
connection: this.#connection,
6161
prefix: this.createNamespacePrefix(namespace),

packages/bentocache/tests/bus/bus.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from '@japa/runner'
22
import { setTimeout } from 'node:timers/promises'
33

4-
import { Redis } from '../../src/drivers/redis.js'
4+
import { RedisDriver } from '../../src/drivers/redis.js'
55
import { CacheFactory } from '../../factories/cache_factory.js'
66
import { MemoryBus } from '../../src/bus/drivers/memory_bus.js'
77
import { ChaosBus } from '../../test_helpers/chaos/chaos_bus.js'
@@ -138,7 +138,7 @@ test.group('Bus synchronization', () => {
138138
assert,
139139
cleanup,
140140
}) => {
141-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
141+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
142142

143143
cleanup(() => remoteDriver.disconnect().catch(() => {}))
144144

packages/bentocache/tests/cache/local_cache.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { test } from '@japa/runner'
22

3-
import { Memory } from '../../src/drivers/memory.js'
3+
import { MemoryDriver } from '../../src/drivers/memory.js'
44
import { TestLogger } from '../../test_helpers/test_logger.js'
55
import { LocalCache } from '../../src/cache/facades/local_cache.js'
66
import { CacheEntryOptions } from '../../src/cache/cache_entry/cache_entry_options.js'
77

88
test.group('Local Cache', () => {
99
test('logically expire should works', ({ assert }) => {
10-
const localCache = new LocalCache(new Memory(), new TestLogger())
10+
const localCache = new LocalCache(new MemoryDriver(), new TestLogger())
1111
const options = new CacheEntryOptions({ ttl: '30m' })
1212

1313
const logicalExpiration = Date.now() + 1000 * 60 * 30
@@ -25,7 +25,7 @@ test.group('Local Cache', () => {
2525
})
2626

2727
test('logically expire should keep the same physical ttl', ({ assert }) => {
28-
const driver = new Memory()
28+
const driver = new MemoryDriver()
2929
const localCache = new LocalCache(driver, new TestLogger())
3030
const options = new CacheEntryOptions({ ttl: '30m' })
3131

packages/bentocache/tests/cache/remote_cache.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from '@japa/runner'
22

3-
import { Redis } from '../../src/drivers/redis.js'
3+
import { RedisDriver } from '../../src/drivers/redis.js'
44
import { TestLogger } from '../../test_helpers/test_logger.js'
55
import { REDIS_CREDENTIALS } from '../../test_helpers/index.js'
66
import { ChaosCache } from '../../test_helpers/chaos/chaos_cache.js'
@@ -10,7 +10,7 @@ import { CacheEntryOptions } from '../../src/cache/cache_entry/cache_entry_optio
1010
test.group('Remote Cache', () => {
1111
test('should rethrows errors if suppressL2Errors is disabled', async ({ assert, cleanup }) => {
1212
const logger = new TestLogger()
13-
const chaosCacheDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
13+
const chaosCacheDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
1414
const cache = new RemoteCache(chaosCacheDriver, logger)
1515

1616
cleanup(() => chaosCacheDriver.disconnect())
@@ -30,7 +30,7 @@ test.group('Remote Cache', () => {
3030

3131
test('should ignore errors if suppressL2Errors is enabled', async ({ assert, cleanup }) => {
3232
const logger = new TestLogger()
33-
const chaosCacheDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
33+
const chaosCacheDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
3434
const cache = new RemoteCache(chaosCacheDriver, logger)
3535

3636
cleanup(() => chaosCacheDriver.disconnect())

packages/bentocache/tests/cache/stampede_protection.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test } from '@japa/runner'
22
import { setTimeout } from 'node:timers/promises'
33

4-
import { Redis } from '../../src/drivers/redis.js'
5-
import { Memory } from '../../src/drivers/memory.js'
4+
import { RedisDriver } from '../../src/drivers/redis.js'
5+
import { MemoryDriver } from '../../src/drivers/memory.js'
66
import { CacheFactory } from '../../factories/cache_factory.js'
77
import { REDIS_CREDENTIALS, throwingFactory } from '../../test_helpers/index.js'
88

@@ -39,7 +39,7 @@ test.group('Cache | Stampede protection', () => {
3939
})
4040

4141
test('multiple concurrent calls should ask remote only once', async ({ assert }) => {
42-
class RemoteDriver extends Memory {
42+
class RemoteDriver extends MemoryDriver {
4343
askedKeys: string[] = []
4444

4545
get(key: string) {
@@ -145,7 +145,7 @@ test.group('Cache | Stampede protection', () => {
145145
.with([100, 1000, 10_000])
146146
.run(async ({ assert }, concurrency) => {
147147
const { cache } = new CacheFactory()
148-
.merge({ l1Driver: new Memory({ maxSize: 100, prefix: 'test' }) })
148+
.merge({ l1Driver: new MemoryDriver({ maxSize: 100, prefix: 'test' }) })
149149
.create()
150150

151151
let factoryCalls = 0
@@ -169,7 +169,7 @@ test.group('Cache | Stampede protection', () => {
169169
.disableTimeout()
170170
.run(async ({ assert }, concurrency) => {
171171
const { cache } = new CacheFactory()
172-
.merge({ l2Driver: new Redis({ connection: REDIS_CREDENTIALS }) })
172+
.merge({ l2Driver: new RedisDriver({ connection: REDIS_CREDENTIALS }) })
173173
.create()
174174

175175
let factoryCalls = 0

packages/bentocache/tests/cache/two_tier.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from '@japa/runner'
22
import { setTimeout } from 'node:timers/promises'
33

4-
import { Redis } from '../../src/drivers/redis.js'
4+
import { RedisDriver } from '../../src/drivers/redis.js'
55
import { TestLogger } from '../../test_helpers/test_logger.js'
66
import { CacheFactory } from '../../factories/cache_factory.js'
77
import { MemoryBus } from '../../src/bus/drivers/memory_bus.js'
@@ -418,7 +418,7 @@ test.group('Cache', () => {
418418
})
419419

420420
test('rethrows error when suppressL2Errors is false', async ({ assert }) => {
421-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
421+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
422422

423423
const { cache } = new CacheFactory()
424424
.merge({ l2Driver: remoteDriver, gracePeriod: { enabled: true, duration: '2h' } })
@@ -537,7 +537,7 @@ test.group('Cache', () => {
537537
})
538538

539539
test('deleteMany should throw if remote fail and suppressL2Errors is on', async ({ assert }) => {
540-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
540+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
541541
const { cache, local, stack } = new CacheFactory()
542542
.merge({ l2Driver: remoteDriver })
543543
.withL1L2Config()
@@ -580,7 +580,7 @@ test.group('Cache', () => {
580580
})
581581

582582
test('a deleteMany should delete others local cache even if remote fail', async ({ assert }) => {
583-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
583+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
584584

585585
const [cache1, local1, , stack] = new CacheFactory()
586586
.merge({ l2Driver: remoteDriver })
@@ -631,7 +631,7 @@ test.group('Cache', () => {
631631
})
632632

633633
test('delete should throw if remote fail and suppressL2Errors is on', async ({ assert }) => {
634-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
634+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
635635

636636
const { cache, local, stack } = new CacheFactory()
637637
.merge({ l2Driver: remoteDriver })
@@ -676,7 +676,7 @@ test.group('Cache', () => {
676676
})
677677

678678
test('a delete should delete others local cache even if remote fail', async ({ assert }) => {
679-
const remoteDriver = new ChaosCache(new Redis({ connection: REDIS_CREDENTIALS }))
679+
const remoteDriver = new ChaosCache(new RedisDriver({ connection: REDIS_CREDENTIALS }))
680680

681681
const [cache1, local1, , stack] = new CacheFactory()
682682
.merge({ l2Driver: remoteDriver })

packages/bentocache/tests/drivers/dynamodb.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from '@japa/runner'
22
import { DeleteTableCommand, CreateTableCommand, DynamoDBClient } from '@aws-sdk/client-dynamodb'
33

4-
import { DynamoDB } from '../../src/drivers/dynamodb.js'
4+
import { DynamoDbDriver } from '../../src/drivers/dynamodb.js'
55
import { registerCacheDriverTestSuite } from '../../test_helpers/driver_test_suite.js'
66

77
const dynamoClient = new DynamoDBClient({
@@ -48,7 +48,7 @@ test.group('DynamoDB driver', (group) => {
4848
group,
4949
supportsMilliseconds: false,
5050
createDriver: (options) => {
51-
return new DynamoDB({
51+
return new DynamoDbDriver({
5252
prefix: 'japa',
5353
region: 'eu-west-3',
5454
endpoint: process.env.DYNAMODB_ENDPOINT,
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from '@japa/runner'
22
import { fileURLToPath } from 'node:url'
33

4-
import { File } from '../../src/drivers/file.js'
4+
import { FileDriver } from '../../src/drivers/file.js'
55
import { BASE_URL } from '../../test_helpers/index.js'
66
import { registerCacheDriverTestSuite } from '../../test_helpers/driver_test_suite.js'
77

@@ -10,7 +10,7 @@ test.group('File driver', (group) => {
1010
test,
1111
group,
1212
createDriver: (options) => {
13-
return new File({ prefix: 'japa', directory: fileURLToPath(BASE_URL), ...options })
13+
return new FileDriver({ prefix: 'japa', directory: fileURLToPath(BASE_URL), ...options })
1414
},
1515
})
1616
})

packages/bentocache/tests/drivers/memory.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { test } from '@japa/runner'
22

3-
import { Memory } from '../../src/drivers/memory.js'
3+
import { MemoryDriver } from '../../src/drivers/memory.js'
44
import { registerCacheDriverTestSuite } from '../../test_helpers/driver_test_suite.js'
55

66
test.group('Memory Driver', (group) => {
77
registerCacheDriverTestSuite({
88
test,
99
group,
10-
createDriver: (options) => new Memory({ maxItems: 1000, prefix: 'japa', ...options }),
10+
createDriver: (options) => new MemoryDriver({ maxItems: 1000, prefix: 'japa', ...options }),
1111
})
1212

1313
test('should not store items exceeding maxEntrySize', async ({ assert }) => {
14-
const cache = new Memory({
14+
const cache = new MemoryDriver({
1515
maxSize: 1024,
1616
maxEntrySize: 100,
1717
})
@@ -30,7 +30,7 @@ test.group('Memory Driver', (group) => {
3030
})
3131

3232
test('should not exceed the store maxSize', async ({ assert }) => {
33-
const cache = new Memory({
33+
const cache = new MemoryDriver({
3434
maxSize: 200,
3535
})
3636

0 commit comments

Comments
 (0)