Writing to a cache key

Using the official SDK is the recommended way to write to a cache key.

Writing to a cache key using the SDK

POST
https://{your-project-name}.api.fireboost.io/v1/cache/set

use FireboostIO\SDK\CacheManager;
use FireboostIO\SDK\Adapter\SessionAdapter;

// Create a CacheManager instance with default SessionAdapter
$apiKey = 'your-api-key'; // Or set FIREBOOST_API_KEY environment variable
$cacheManager = new CacheManager(new SessionAdapter(), $apiKey);

// Save data to cache
$cacheKey = 'your-cache-key';
$content = ['name' => 'Example', 'value' => 123];
$isPublic = false; // Set to true for publicly accessible cache

$response = $cacheManager->saveCache($cacheKey, $content, $isPublic);

Writing to a cache key using the the libraries

This solution works best if you're customizing how you interact with the API.

Once you have the JWT token, set it in the client and use that client for API calls.

POST
https://{your-project-name}.api.fireboost.io/v1/cache/set
use FireboostIO\Model\SetInput;

$jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...';

$config = new Configuration();
$config->setAccessToken($jwt);
$config->setApiKeyPrefix('bearer', 'Bearer');
$api = new FireboostIO\Api\FireboostApi(null, $config);

$response = $api->setCache(new SetInput([
    'cache_key' => 'test.com/news/post/1234',
    'content' => json_encode(['name' => 'Example', 'value' => 123]),
    'is_public' => true // or false
]));

Was this page helpful?