---
name: "ldap_cache"
section: "3"
platform: "linux"
package: "libldap2-dev"
version: "2.0.23-6.3"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/ldap_cache"
---

# ldap\_cache(3)

LDAP client caching routines

## NAME

ldap\_enable\_cache, ldap\_disable\_cache, ldap\_destroy\_cache, ldap\_flush\_cache, ldap\_uncache\_entry, ldap\_uncache\_request, ldap\_set\_cache\_options - LDAP client caching routines

## SYNOPSIS

```
#include <ldap.h>
```

**ldap\_enable\_cache( ld, timeout, maxmem )** LDAP	\*ld; long	timeout; long	maxmem;

**void ldap\_disable\_cache( ld )** LDAP	\*ld;

**void ldap\_destroy\_cache( ld )** LDAP	\*ld;

**void ldap\_flush\_cache( ld )** LDAP	\*ld;

**void ldap\_uncache\_entry( ld, dn )** LDAP	\*ld; char	\*dn;

**void ldap\_uncache\_request( ld, msgid )** LDAP	\*ld; int	msgid;

**void ldap\_set\_cache\_options( ld, opts )** LDAP		\*ld; unsigned long	opts;

## DESCRIPTION

These routines are used to control the behavior of the **experimental** client caching of [**ldap\_search**(3)](/ldap_search/3.md) and [**ldap\_compare**(3)](/ldap_compare/3.md) operations.  By default, the cache is disabled and no caching is done.  Enabling the cache can greatly improve performance and reduce network bandwidth when a client DUA makes repeated requests.

**ldap\_enable\_cache()** should be called to turn on local caching or to change cache parameters (lifetime of cached requests and memory used). The *ld* parameter should be the result of a successful call to [**ldap\_open**(3)](/ldap_open/3.md). The *timeout* is specified in seconds, and is used to decide how long to keep cached requests.  The *maxmem* value is in bytes, and is used to set an upper bound on how memory the cache will use.  You can specify 0 for *maxmem* to restrict the cache size by the *timeout* only.  The first call to ldap\_enable\_cache creates the cache; subsequent calls re-enable the cache and set the timeout and memory values.

**ldap\_disable\_cache()** temporarily disables use of the cache (new requests are not cached and the cache is not checked when returning results).  It does not delete the cache contents.

**ldap\_destroy\_cache()** turns off caching and completely removes the cache from memory.

**ldap\_flush\_cache()** deletes the cache contents, but does not effect it in any other way.

**ldap\_uncache\_entry()** removes all requests that make reference to the distinguished name *dn* from the cache.  It should be used, for example, after doing an [**ldap\_modify**(3)](/ldap_modify/3.md) call involving *dn*.

**ldap\_uncache\_request()** removes the request indicated by the LDAP request id *msgid* from the cache.

**ldap\_set\_cache\_options()** is used to change caching behavior.  The current supported options are **LDAP\_CACHE\_OPT\_CACHENOERRS** to suppress caching of any requests that result in an error, and **LDAP\_CACHE\_OPT\_CACHEALLERRS** to enable caching of all requests.  The default behavior is to not cache requests that result in errors, except that request that result in the error **LDAP\_SIZELIMIT\_EXCEEDED** are cached.

## ERRORS

**ldap\_enable\_cache()** returns 0 upon success, and -1 if it is unable to allocate space for the cache.  All the other calls are declared as void and return nothing.

## SEE ALSO

[**ldap**(3)](/ldap/3.md), [**ldap\_search**(3)](/ldap_search/3.md), [**ldap\_compare**(3)](/ldap_compare/3.md)

## ACKNOWLEDGEMENTS

**OpenLDAP** is developed and maintained by The OpenLDAP Project (http://www.openldap.org/). **OpenLDAP** is derived from University of Michigan LDAP 3.3 Release.
