# DeviceAtlas Data File Optimizer #
Optimization for downloaded data file inside a web application.
### Overview ###
In a web application, the first request after a data file update will experience
a small lag. To eliminate this lag, it is necessary to optimize the data file.
This tool pre-optimizes a data file downloaded from the DeviceAtlas website.
The API will then directly use the optimized data.
Note: To manually update the optimization cache with this command line tool
it is recommended to turn off the DeviceApi data file changes check which would
be unnecessary:
**Inside a web application**
```php
use DeviceAtlas\Device\DeviceApiWeb;
use DeviceAtlas\Device\Config;
$config = new Config();
$config->setIgnoreDataFileChanges(true);
$deviceApi = new DeviceApiWeb($config);
$deviceApi->loadDataFromFile();
```
**Optimize the data file**
The following command can be run once there is new data file.
```bash
php ExtraTools/data-file-optimizer/main.php -d /path/to/datafile.json
```
### Other usages ###
**Clear the optimization cache**
```bash
php ExtraTools/data-file-optimizer/main.php -c
```
**Analyses speed and memory performance**
```bash
php ExtraTools/data-file-optimizer/main.php -a /path/to/datafile.json
```
#### Custom temp directory ####
By default, the optimized data caches will be put inside the system temp directory,
however it can be changed using this config option:
```php
$config->setOptimizerTempDir('/path/to/my/temp-directory');
```
When using custom temp directory, this information must be also passed to the script:
```bash
php ExtraTools/data-file-optimizer/main.php ... -t /path/to/my/temp-directory
```
e.g.
```bash
php ExtraTools/data-file-optimizer/main.php -d /path/to/datafile.json -t /path/to/my/temp-directory
php ExtraTools/data-file-optimizer/main.php -a /path/to/datafile.json -t /path/to/my/temp-directory
php ExtraTools/data-file-optimizer/main.php -f /path/to/datafile.json -t /path/to/my/temp-directory
```
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_ Copyright (c) DeviceAtlas Limited 2023. All Rights Reserved. _
_ https://deviceatlas.com _