PHP code example of pteal79 / mobile-file-cache

1. Go to this page and download the library: Download pteal79/mobile-file-cache 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/ */

    

pteal79 / mobile-file-cache example snippets


return [
    'disk' => env('MOBILE_FILE_CACHE_DISK', 'mobile_public'),
    'directory' => env('MOBILE_FILE_CACHE_DIRECTORY', 'cached_files'),
    'cleanup_after_days' => 30,
    'max_file_size_mb' => 30,
    'timeout' => 60,
    'allowed_mime_types' => [
        'application/pdf',
        'image/jpeg',
        'image/png',
        'image/gif',
        'image/webp',
        'image/svg+xml',
    ],
    'queue' => [
        'tries' => 3,
        'backoff' => [5, 30, 120],
        'http_retries' => 3,
        'http_retry_sleep_ms' => 250,
    ],
];

use MobileFileCache;

$displayableUrl = MobileFileCache::get($remoteUrl);
$absolutePath = MobileFileCache::get($remoteUrl, true);

MobileFileCache::cache($remoteUrl);
MobileFileCache::invalidate($remoteUrl);

$totalBytes = MobileFileCache::totalCacheSize();
$totalFiles = MobileFileCache::totalCacheRecords();

MobileFileCache::clearAged();
MobileFileCache::clear();

public function created(SomeModel $model): void
{
    if ($model->remote_image_url) {
        MobileFileCache::cache($model->remote_image_url);
    }
}
bash
composer vendor:publish --tag=mobile-file-cache-config
php artisan vendor:publish --tag=mobile-file-cache-migrations
php artisan migrate