Skip to content

Commit

Permalink
add listener for session changes to ensure the cache is updated as th…
Browse files Browse the repository at this point in the history
…e scope entries change
  • Loading branch information
jclausen committed Apr 15, 2024
1 parent c5910ad commit 7615917
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ortus/boxlang/runtime/application/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public SessionScope getSessionScope() {
return sessionScope;
}

public Application getApplication() {
return this.application;
}

public void shutdown() {
// Any buffer output in this context will be discarded
if ( startingListener != null ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ortus.boxlang.runtime.types.listeners;

import ortus.boxlang.runtime.application.Session;
import ortus.boxlang.runtime.scopes.Key;

public class SessionListener {

private final Session session;

public SessionListener( Session session ) {
this.session = session;
}

/**
* Call when a value is being changed in an IListenable
*
* @param key The key of the value being changed. For arrays, the key will be 1-based
* @param newValue The new value (null if being removed)
* @param oldValue The old value (null if being added)
*
* @return The new value to be set (you can override)
*/
public Object notify( Key key, Object newValue, Object oldValue ) {
this.session.getApplication().getSessionsCache().set( this.session.getID().getName(), this.session );
return null;
}

}

0 comments on commit 7615917

Please sign in to comment.