Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Add :ttl configuration option#1

Merged
pkarman merged 1 commit intomasterfrom
pek-alternate-expiration-config-key
Mar 3, 2017
Merged

Add :ttl configuration option#1
pkarman merged 1 commit intomasterfrom
pek-alternate-expiration-config-key

Conversation

@pkarman
Copy link

@pkarman pkarman commented Mar 1, 2017

Why: The :expire_after config option controls both the Redis
session expiration and the expiration of the Rails session cookie.
Adding a new config option :ttl allows those controls to be
managed separately.

The most common case would be if you wanted the Rails cookie
to expire when the browser is closed, as it would if :expire_after
were set to nil.

end

it 'assigns the :ttl option to @default_options' do
expect(default_options[:ttl]).to eq(60 * 120)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can assign 60 * 120 to a variable and ref that here and on L72 so it's more obvious where it's coming from?

alias write_session set_session

def get_expiry(env, options)
opts = options || env.fetch(ENV_SESSION_OPTIONS_KEY)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about calling this expiry instead of opts ? That seems clear-er to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not really expiry though -- its all the session storage options.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you are right, I was misreading what was up there before. My basic feeling on this is that having options and opts vars in the same method is tricky. If we can find slightly better names for one or both, that would be 🆒

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about redis_options instead of opts ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or session_storage_options ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! both work for me

@pkarman pkarman force-pushed the pek-alternate-expiration-config-key branch 2 times, most recently from c8131fe to 101b938 Compare March 1, 2017 18:07
@pkarman
Copy link
Author

pkarman commented Mar 1, 2017

session_storage_options it is @jessieay

Copy link

@jessieay jessieay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐶

alias write_session set_session

def get_expiry(env, options)
session_storage_options = options || env.fetch(ENV_SESSION_OPTIONS_KEY)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will ENV_SESSION_OPTIONS_KEY always be present? If not, then perhaps use fetch with a default value, such as env.fetch(ENV_SESSION_OPTIONS_KEY, {})? That way, if session_storage_options is nil, session_storage_options[:ttl] won't raise a NoMethodError.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code seems to assume that env.fetch(ENV_SESSION_OPTIONS_KEY) always exists, since I just cut/pasted that line. Happy to be a little defensive though.

@zachmargolis
Copy link

Is it worth updating the README as well?

@pkarman pkarman force-pushed the pek-alternate-expiration-config-key branch 2 times, most recently from 02a72cb to bdd1b2b Compare March 1, 2017 21:32
@pkarman
Copy link
Author

pkarman commented Mar 1, 2017

@zachmargolis README updated.

@pkarman
Copy link
Author

pkarman commented Mar 1, 2017

@monfresh @zachmargolis comments addressed, thanks. PTAL

README.md Outdated
redis: {
expire_after: 120.minutes,
expire_after: 120.minutes, # cookie expiration
ttl: 120.minutes, # Redis expiration

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"redis expiratoin, defaults to expire_after" ?

Copy link

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

**Why**: The :expire_after config option controls both the Redis
session expiration and the expiration of the Rails session cookie.
Adding a new config option :ttl allows those controls to be
managed separately.

The most common case would be if you wanted the Rails cookie
to expire when the browser is closed, as it would if :expire_after
were set to `nil`.
@pkarman pkarman force-pushed the pek-alternate-expiration-config-key branch from bdd1b2b to 71053a9 Compare March 3, 2017 17:27
@pkarman pkarman merged commit 101df47 into master Mar 3, 2017
@pkarman pkarman deleted the pek-alternate-expiration-config-key branch March 3, 2017 17:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants