# DeviceAtlas Device Identification API Config #
There are multiple factors which might affect API behaviour and performance.
* General tips
* Config class
### General tips ###
* JVM Settings
#### JVM Settings ####
The Java Virtual Machine Settings can greatly influence the performance and
the memory usage. The following settings are the common values to fit most of
the cases :
- -Xms minimum 300 MB.
- -XX:+UseParallelGC.
- -XX:+UseNuma if the API runs under a NUMA server.
### Config class ###
DeviceAtlas DeviceApi Config class provides options to customize the API
behaviour in terms of memory use, caching, performance and device properties.
* Cache Settings
* Include User-Agent properties
* Include language properties
* Return NULL when there are no properties
* Client-side cookie name
#### Cache Settings ####
An internal cache can be used to gain performance. The number of entries can be
changed. Note that if it set to zero, the cache is disabled.
**Config methods**
```
setMaxCacheEntries()
getMaxCacheEntries()
```
**Default value**
4096
#### Include User-Agent properties ####
Boolean value to enable/disable the addition of User-Agent properties to the
identification. They are also known as "dynamic" properties as they can be detected
on the fly by directly parsing the User-Agent.
Enabling this property will worsen API identification performance. If you don't need
these properties, then set it to false.
User-Agent/Dynamic properties: browserName, browserVersion,
browserRenderingEngine, osName, osVersion
**Config methods**
```
setIncludeUaProps(true/false)
getIncludeUaProps()
```
**Default value**
true
#### Include language properties ####
Boolean value to enable/disable the addition of client's language and locale
preferences to the device property set.
If you don't need these properties, then set it to false.
Language properties: language, languageLocale
**Config methods**
```
setIncludeLangProps(true/false)
getIncludeLangProps()
```
**Default value**
true
#### Return NULL when there are no properties ####
Boolean value to make the API either return NULL if the property set to return
is empty, or a Properties object with no values inside.
**Config methods**
```
setReturnNullWhenNoProperties(true/false)
getReturnNullWhenNoProperties()
```
**Default value**
false
#### Client-side cookie name ####
Name of the cookie where the Client-side properties will be saved in.
When using getProperties() method in a web application (DeviceApiWeb), the
identification will automatically use the content of this cookie, if it exists.
If you want the Client-side properties to be used add the DeviceAtlas client
side component (JavaScript lib) to your web-site pages.
When the User-Agent or HTTP headers are passed manually to getProperties(), the
Client-side properties can be also manually passed to this method as second
parameter.
Note that this config is only used as an argument of getProperties().
If you set the cookie name to NULL, then the Client-side properties cookie will
be ignored.
**Config methods**
```
setCookieName(cookieName)
getCookieName()
```
**Default value**
"DAPROPS"
### How it works ###
Translating into code how the API settings are used, it is as simple as having
an instance of the mobi.mtld.da.device.Config class into the
mobi.mtld.da.device.DeviceApi object and the respective Config public methods
to check the wished settings and make the API work according to them.
#### Use of the default settings ####
When a new instance of the mobi.mtld.da.device.DeviceApi class is created,
internally another instance of the mobi.mtld.da.device.Config class is generated
with the default settings.
```java
deviceApi = new DeviceApi();
```
#### Use of custom settings ####
In order to use custom settings, it is required to explicitly create a
Config object, set the settings and pass it to the DeviceApi instance.
```java
/* Preferred method */
config = new Config();
config.setMaxCacheEntries(1024);
config.setIncludeUaProps(false);
deviceApi = new DeviceApi(config);
```
```java
/* Alternative method */
deviceApi = new DeviceApi();
config = new Config();
config.setIncludeUaProps(false);
deviceApi.setConfig(config);
```
### Example of use case ###
For the scenario your system works, it is highly recommended to configure the
API with the most convenient settings in order to enhance performance, memory
footprint and, in general, provide a better user experience.
```java
/* Reduce response time and memory footprint for a web application */
config = new Config();
// Set the number of maximum entries held in the internal cache.
config.setMaxCacheEntries(256);
// Boost API performance by ignoring dynamic properties if they are not part of
// the property set you expect.
config.setIncludeUaProps(false);
// Ignore language and locale properties if they are not needed.
config.setIncludeLangProps(false);
// Finally set the config to our new instance of the DeviceAtlas API.
deviceApi = new DeviceApi(config);
```
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas Limited 2022. All Rights Reserved. _
_ https://deviceatlas.com _