title: Java persistence layer synchronization
body: <p><strong>Situation:</strong>
  I have set up a basic system to cache Team objects inside a TeamManager. Essentially all it is is a HashMap that stores the teams by name. TeamManager also has an IDataManager objects which is the persistence layer that TeamManager writes to, whether it is a SQL database or a flat file. Let's assume for the sake of this situation that all I am using is a flat file method for saving Team data.</p>
  
  <p><strong>Problem:</strong>
  I have a function in TeamManager, "getTeam(String teamName)" which returns a reference to a Team object in the HashMap. If another class calls this method and changes something inside the Team object I need it to be undated in in the persistence layer. The problem is that TeamManager does not know when a change has been made to Team to know to update it.</p>
  
  <p><strong>Question:</strong>
  What is the best way to go about solving this issue?</p>
  
  <p>• I could implement a periodic write to the persistence layer, but this is a bandaid fix...</p>
  
  <p>• I could get rid of the HashMap entirely from TeamManager and make it only reference what is in the persistence layer, but this adds overhead...</p>
  
  <p>• I could try to move all setters for accessing team data to TeamManager in order to control when things are updated where, but this would touch too many classes and take too much time...</p>
  
  <p>Does anyone have any suggestions on what I might do to resolve this issue or further explain my problem?</p>
  
  <p>Thanks in advance.</p>