SessionExists()

I added a sessionExists() function in Lucee 6.2, it’s used to avoid creating a session if one doesn’t exist, as structKeyExists(session, "anything") ends up creating a session

Anyone using it?

2 Likes

@Zackster Yes … I am!

I’m using it for example in my POST-redirect-GET patterns before checking for the existence of a session variable, like so:

if (SessionExists() && !isNull(session.exampleData)) {
	sState = session.exampleData; // s is my prefix for struct
	// prepare status output and form values from session data
	// ...
	session.delete("exampleData");
}

That way I’m avoiding the Catch-22 of unnecessarily creating a session when checking to see whether a session var exists!

I’ve been a cfml dev since '97 so a lot of my code is still so old that it predates sessions, thus my user authentication for example was done with simple cookies and a tblUser in the database, which is pretty much what sessions do.

Thus it wasn’t until just recently via my desire to implement the PRG pattern that I started using sessions.

One of my concerns for resource usage and performance was that I didn’t want a session fired up for every http request, only for when a PRG was involved.

Then I found your new SessionExists() to solve that issue.

I appreciate the work you did and it was perfect timing for my needs!

1 Like

awesome mate

Next up I’m thinking about a sessionTouch()

https://luceeserver.atlassian.net/browse/LDEV-5941

2 Likes

I’m for sure! Thanks you!!

1 Like

Will look into this, we use a lot of session stuff, so may be good to see where it could fit in!

1 Like