Skip to content

Commit 2564e00

Browse files
committed
feat(touch): adding skip touch option on config
1 parent 3f5cfd7 commit 2564e00

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/express-session-etcd3.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ export interface Etcd3StoreOptions extends IOptions {
2222
* Defaults to `sess`.
2323
*/
2424
prefix?: string
25+
skipTouch?: boolean
2526
}
2627

2728
/**
2829
* Default configuration values for the etcd v3 options
2930
*/
3031
export const defaultOptions: Etcd3StoreOptions = Object.freeze({
3132
prefix: 'sess',
32-
hosts: '127.0.0.1:2379'
33+
hosts: '127.0.0.1:2379',
34+
skipTouch: false
3335
})
3436

3537
/**
@@ -109,6 +111,10 @@ export default class Etcd3Store extends Store {
109111
* potentially resetting the idle timer.
110112
*/
111113
touch = (sid: string, session: Express.SessionData, callback: (err: any) => void): void => {
114+
if (this.config.skipTouch) {
115+
this.debug('SKIP TOUCH "%s"', sid)
116+
return
117+
}
112118
this.debug('TOUCH "%s" %O', sid, session)
113119
this.set(sid, session, callback)
114120
}

test/express-session-etcd3.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ describe('Etcd3Store test suit', () => {
181181
subject.touch(sessionData.sid, sessionData, callback)
182182
expect(subject.set).toHaveBeenCalledWith(sessionData.sid, sessionData, callback)
183183
})
184+
185+
it('should not set it again if skipTouch is true at the adapter config', async () => {
186+
const { subject, client } = await createSubject({ skipTouch: true })
187+
jest.spyOn(subject, 'set').mockImplementation(jest.fn())
188+
const callback = jest.fn()
189+
subject.touch(sessionData.sid, sessionData, callback)
190+
expect(subject.set).not.toHaveBeenCalled()
191+
})
184192
})
185193

186194
describe('when getting all the sessions', () => {

0 commit comments

Comments
 (0)