PHP code example of andrewdalpino / dataloader-php
1. Go to this page and download the library: Download andrewdalpino/dataloader-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
andrewdalpino / dataloader-php example snippets
$batchFunction = function ($keys) {
return Redis::mget(...$keys);
};
$loader = new BatchingDataLoader($batchFunction);
$cacheKeyFunction = function ($entity, $index) {
return $entity['id'];
};
$loader = new BatchingDataLoader($batchFunction, $cacheKeyFunction);
use AndrewDalpino\DataLoader\BatchingDataLoader;
use App\User;
// Required batch function to load users with supplied array of buffered $keys.
$batchFunction = function ($keys) {
return User::findMany($keys);
};
// Optional cache key function returns the primary key of the user entity.
$cacheKeyFunction = function ($user, $index) {
return $user->id;
};
$userLoader = new BatchingDataLoader($batchFunction, $cacheKeyFunction);
$options = [
'batch_size' => 1000 // The max number of entities to batch load in a single round trip from storage.
];
$loader = new BatchingDataLoader($batchFunction, $cacheKeyFunction, $options);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.