Dave Merrill
08/12/2024, 5:52 PMdenny
08/12/2024, 8:00 PMAdam Cameron
Dave Merrill
08/14/2024, 12:41 PMDave Merrill
08/14/2024, 12:58 PMAdam Cameron
Adam Cameron
// ScopeAdapter.cfc
abstract component {
public function init(required scope) {
variables.scope = arguments.scope
}
public any function get(required string key) {
return variables.scope[key]
}
public void function set(required string key, required value) {
variables.scope[key] = value
}
abstract public void function runSynchronised(required function callback, struct lockParams={})
}
// SessionScopeAdapter.cfc
component extends=ScopeAdapter {
public void function runSynchronised(required function callback, struct lockParams={}) {
lock type="session" attributeCollection=arguments.lockParams {
arguments.callback()
}
}
}
// SomethingNeedingSessionStuff.cfc
component {
public function init(required SessionScopeAdapter sessionContext) {
variables.sessionContext = arguments.sessionContext
}
public doTheThing() {
variables.sessionContext.runSynchronised(() => {
local.theUser = variables.sessionContext.get("user")
// do stuff with other services
local.theUser.newThing = whatevs
variables.sessionContext.set("user", local.theUser)
}, {throwOnTimeout=true, timeout=60, type="exclusive"})
}
}
Short version: your adapter has a get and set method to stuff out and in to the scope.
And there's an example of a method to synchronise some code to prevent a race condition.Adam Cameron
Dave Merrill
08/15/2024, 1:53 PMAdam Cameron
bdw429s
08/15/2024, 4:35 PMbdw429s
08/15/2024, 4:36 PMbdw429s
08/15/2024, 4:36 PMdenny
08/15/2024, 5:13 PMAdam Cameron
denny
08/15/2024, 10:45 PMdenny
08/16/2024, 4:33 PMDave Merrill
08/16/2024, 7:19 PMdenny
08/16/2024, 8:25 PMDave Merrill
08/16/2024, 9:25 PMbkbk
08/19/2024, 3:55 PMbkbk
08/19/2024, 9:08 PMif (!structKeyExists(application, "someVar")) {
lock type="exclusive" timeout="10" scope="application"
{
// application.someVar cache code goes here
}
}