spring-projects / spring-projects/spring-session

Provide DeltaAwareSessionAttribute interface

Open
#560 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

We have been bitten a few times by the behaviour that a session attribute is only written to the backing store if session.setAttribute() has been called. That is, the following pseudocode will not persist config to the backing store, because the session is not aware that it changed:

MyConfigAttribute config = session.getAttribute("config-attribute")
config.setSomeValue()

Now, it can be fixed easily enough, but this forces the attribute to be written every time, even if nothing changed:

MyConfigAttribute config = session.getAttribute("config-attribute")
session.setAttribute("config-attribute", config);
config.setSomeValue()

It would be nice if there was some way of indicating that the attribut may change, and have the session store check this during persisting. One way would be to have an interface that could be implemented by the attribute classes, which would repsonsd to queries to whether it changed. (The implementation would probably be to use a transient field).

public class MyConfigAttribute implements DeltaAwareSessionAttribute [
   boolean sessionAttributeHasChanged() { ... }
}

With this, the session store would have to understand this. The simplest implementation would be to instrument getAttribute, so that when the client calls session.getAttribute("config-attribute"), the store would "tag" this attribute for later checking, and then let the attribute decide for itself whether the session has changed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Spring Session handles getAttribute and setAttribute and how session attributes are persisted to the backing store. Define the interface and persistence behavior, then add tests showing that a mutated attribute is persisted without an unconditional write and that unchanged attributes are not rewritten.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.