<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: LDAP API call cache</title><link>https://answers.axonivy.com/questions/1142/ldap-api-call-cache</link><description>&lt;p&gt;Hi, we have some performance problems by communication with LDAP after switching from 4.3 to 5.0. I have two questions&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;were there any changes intern by calling API (see bellow)&lt;/li&gt;
&lt;li&gt;are there any API methods which doesn't communicate with LDAP (using direct only ivy system database) ?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Especially we use the following method&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ISecurityContext.findRole(...)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IWorkflowSession.hasRole(IRole, Boolean)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</description><atom:link href="https://answers.axonivy.com/questions/1142/ldap-api-call-cache" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 04 Feb 2015 11:34:58 -0500</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/1142/ldap-api-call-cache/1148</link><description>&lt;p&gt;A call to the method &lt;strong&gt;&lt;code&gt;ISecurityContext.findRole(...)&lt;/code&gt;&lt;/strong&gt; will result in a query to the system database, because the roles are stored there, so no query to the external security system (LDAP) is needed.&lt;/p&gt;
&lt;p&gt;The first call to the methode &lt;strong&gt;&lt;code&gt;IWorkflowSession.hasRole(IRole, Boolean)&lt;/code&gt;&lt;/strong&gt; could results in a query to the external security system (LDAP). Latest all following calls within 5 minutes will use the cache of the first call, independent of the parameter.&lt;/p&gt;
&lt;p&gt;In fact the cache is initialized/handled by the method &lt;code&gt;IUser.getRoles()&lt;/code&gt;, which is called internally by the method &lt;code&gt;IWorkflowSession.hasRole(IRole, Boolean)&lt;/code&gt;. The method &lt;code&gt;IUser.getRoles()&lt;/code&gt; caches the result for 10 seconds on the user-instance (this means, further calls within 10 seconds on the same instance will return the cached result. The method ISecurityContext.findUser(...) will always return a new instance.). However, if the method is called on the current logged-in user the result is cached on the session and has therefore a timeout of 5 minutes.&lt;/p&gt;
&lt;p&gt;In 4.3 only the cache for the current logged-in user exists. The ‘10 second cache’ on any user-instance was introduced with 5.0.15.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE: A code example for clarification:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;IRole.getUsers() / IRole.getAllUsers() is NEVER cached&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IRole role = ISecurityContext.findRole("RoleA"); // only access to system db
role.getUsers(); // first call not cached
role.getUsers(); // subsequent calls not cached
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cache of IUser.getRoles() / IUser.getAllRoles()&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ISecuritySession.findUser("Max").getRoles(); // NOT cached
ISecuritySession.findUser("Max").getRoles(); // NOT cached, because findUser() returns a new instance

IUser user = IWorflowSession.findUser("Max"); // if user is not already synchronized, it will be looked up in the LDAP.
user.getRoles(); // first call NOT cached
user.getRoles(); // subsequent calls are cached, because called on the same instance
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Wed, 04 Feb 2015 11:34:58 -0500</pubDate><guid>https://answers.axonivy.com/questions/1142/ldap-api-call-cache/1148</guid></item></channel></rss>