Global variable or non-persistent entity to trigger db retreive
Hello, Is it possible to create a global variable or non-persistent entity? ---- EDITED ----- This is the use case in short: I have a page that shows an object of entity A. The underlying object or rather associated objects can be updated at any time by all user. I'm estimating <100 concurrent users. When the the object is updated the page needs to update asap (<5s). Sometimes theses updates will come very frequently and sometimes not for hours. Frequent = several times per minute. Current solution: I have connected a persistent ChangedHelper, CH, entity that has a 1-1 with entity A that only contains the changedDate of entity A. When A is changed, CH is also changed. Then I have a non-persistent entity, Entity NP-A that replicates the data from Entity A. A micro flow timer triggers a micro flow which compares the changed date of the ChangedHelper with the updatedDate of NP-A. If a refresh is needed A is retrieved from the db and NP-A is refreshed with the new data. By using the ChagedHelper I reduced the number of retrieves by approx 20%. Potential issue: With this solution the client still has to do a db query every 5s wich means that the number of calls grows quickly with the number of users. If the MT that check if entity A has been updated instead could compare with a non-persistent entity/global variable it would save a lot of DB calls. Hope this clarifies my questions: Thanks :) Fredrik
Whenever I need a global variable I use the singleton pattern. For mendix that looks something like this.
1) Create a persistant entity e.g. "MyEntity"
2) Create a microflow "DS_MyEntity_GetOrCreate" that attempts to retrieve the enttiy from DB or creates a new one if it is not found in the DB (a good practice is to add the name singleton in the domain model and an annotation that explains how to get an instace)
3) Always use the DS microflow whenever you need access to the global variable.
Hope this helps,
PS: If you want a variable per User or per Session then you should associate "MyEntity" to either the User or Account or Session objects. Update the retrieve in the DS microflow retrieve action to also check this association. Remember you have access to the user and session in each microflow via the variables currentUser and currentSession
Other than a Constant you mean?
You could create a 'AdminSettings' (or 'ApplicationVariables' or whatever) entity which is available to the Admin (and of which only 1 object exists), with variables that can be set and changed: like an 'updateRequired' boolean. This can then be set runtime, and take effect immidiately. When checking as a user you can look at this entity.
Is this what you mean, or did I misinterpret your requirement?
EDIT: looks like I was 19 seconds too slow, good thing is that Andrej suggests a similar solution :)