PHPackages                             gorilladash/laravel-website-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. gorilladash/laravel-website-sdk

ActiveLibrary[Caching](/categories/caching)

gorilladash/laravel-website-sdk
===============================

Laravel SDK for the GorillaDash website GraphQL API with stale-while-revalidate caching for instant SSR.

v0.2.0(today)00MITPHPPHP ^8.3

Since Jun 19Pushed todayCompare

[ Source](https://github.com/GorillaDash/laravel-website-sdk)[ Packagist](https://packagist.org/packages/gorilladash/laravel-website-sdk)[ RSS](/packages/gorilladash-laravel-website-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (8)Versions (4)Used By (0)

GorillaDash Website SDK
=======================

[](#gorilladash-website-sdk)

[![Latest Version](https://camo.githubusercontent.com/d58894e499a7ab0f7a1544b8cd569da19b5f76a97000e044f84eb9182b1cb9f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7061636b61676973742d676f72696c6c61646173682532466c61726176656c2d2d776562736974652d2d73646b2d626c7565)](https://packagist.org)[![License: MIT](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

A Laravel package that connects a client website to the **GorillaDash website GraphQL API**and serves its content through a **stale-while-revalidate (SWR) cache** — so server-rendered pages return **instantly** from cache while fresh data is fetched from the API in the background. The browser never waits on an API call.

> **Live demo:** [website-sdk-demo.gorilladash.com](https://website-sdk-demo.gorilladash.com)— a small Inertia + SSR site that lets you enter credentials, run any of the website GraphQL queries, and watch the cache behaviour (and timings) live.

---

Why
---

[](#why)

Client websites built on GorillaDash need to render marketing/content pages fast. Calling the GraphQL API on every request adds latency and a hard dependency on the API being up. This SDK puts a cache in front of the API with **stale-while-revalidate** semantics:

Cache stateBehaviour**No cache**Block, fetch from the API, store, return.**Younger than TTL** (default 60s)Serve cached. **No API call.****Older than TTL**Serve cached **instantly**, and refresh from the API **in the background** (after the response is sent — no queue worker needed). The next request gets the newer data.Stale data is retained well past the TTL so there is always something to serve, and background refreshes are guarded by a per-key lock to avoid stampedes.

---

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11, 12 or 13

Installation
------------

[](#installation)

The SDK is distributed from a private/VCS repository. Add the source, then require it:

```
// composer.json
"repositories": [
    { "type": "vcs", "url": "git@github.com:gorilladash/laravel-website-sdk.git" }
]
```

```
composer require gorilladash/laravel-website-sdk
php artisan vendor:publish --tag=website-sdk-config   # optional
```

The service provider and the `GorillaDash` facade are auto-discovered.

The provider is built on [spatie/laravel-package-tools](https://github.com/spatie/laravel-package-tools): it extends `PackageServiceProvider` and wires everything declaratively in `configurePackage()` — the config file (published under the `website-sdk-config` tag) and the cache-clear webhook route (`routes/web.php`). Service bindings are registered in the `packageRegistered()` lifecycle hook.

Credentials
-----------

[](#credentials)

From the GorillaDash **website API settings** you get three values. Map them as follows — the public key is **not** used for GraphQL auth:

```
GD_WEBSITE_BASE_URI=https://api.gorilladash.com
GD_WEBSITE_CLIENT_ID=your-website-id        # the website API "ID"
GD_WEBSITE_CLIENT_SECRET=your-access-token   # the "API Access Token"
GD_WEBSITE_CACHE_TTL=60
```

The SDK exchanges these for a bearer token at `{base_uri}/oauth/token`(OAuth2 client-credentials grant) and caches the token automatically.

Configuration
-------------

[](#configuration)

All options live in `config/website-sdk.php` and are env-driven:

OptionEnv varDefaultDescription`base_uri``GD_WEBSITE_BASE_URI``https://api.gorilladash.com`API base URL (token + GraphQL).`client_id``GD_WEBSITE_CLIENT_ID`—Passport OAuth client id (website "ID").`client_secret``GD_WEBSITE_CLIENT_SECRET`—Passport client secret ("API Access Token").`public_key``GD_WEBSITE_PUBLIC_KEY`—Website public key — authenticates the cache-clear webhook (not GraphQL).`cache_ttl``GD_WEBSITE_CACHE_TTL``60`Freshness window (seconds).`cache_store``GD_WEBSITE_CACHE_STORE`app defaultLaravel cache store to use.`cache_prefix``GD_WEBSITE_CACHE_PREFIX``gd_website:`Cache key prefix.`stale_retention_multiplier``GD_WEBSITE_STALE_RETENTION``100`Stale data kept for `cache_ttl × this` (0 = forever).`max_stale_age``GD_WEBSITE_MAX_STALE_AGE``86400`Hard ceiling on stale age (seconds); past it, block and refetch. 0 = disabled.`register_graphql_route``GD_WEBSITE_GRAPHQL_ROUTE``true`Expose the `POST` GraphQL endpoint.`graphql_path``GD_WEBSITE_GRAPHQL_PATH``graphql`Path for the GraphQL endpoint.`register_clear_cache_route``GD_WEBSITE_CLEAR_CACHE_ROUTE``true`Register the cache-clear webhook.`clear_cache_path``GD_WEBSITE_CLEAR_CACHE_PATH``gorilla-dash/clear-cache`Path for the cache-clear webhook.`token_skew``GD_WEBSITE_TOKEN_SKEW``60`Re-exchange the token this many seconds early.`http_timeout``GD_WEBSITE_HTTP_TIMEOUT``10`Per-request timeout (seconds).Usage
-----

[](#usage)

Queries are built with [`mghoneimy/php-graphql-client`](https://github.com/mghoneimy/php-graphql-client)(Packagist: `gmostafa/php-graphql-client`, a dependency of this package). `graphql()` takes a `Query` (or `QueryBuilderInterface`) object; `graphqlWithMeta()` additionally accepts a raw query string.

```
use GorillaDash\WebsiteSdk\Facades\GorillaDash;
use GraphQL\Query;
use GraphQL\RawObject;
use GraphQL\Variable;

// Pass a Query object — returns the GraphQL `data` array (SWR cached):
$query = (new Query('websiteInfo'))->setSelectionSet(['name', 'url']);
$data = GorillaDash::graphql($query);

// With variables — declare them on the query, pass values as the second arg:
$query = (new Query('websitePage'))
    ->setVariables([new Variable('slug', 'String', true)])
    ->setArguments(['slug' => new RawObject('$slug')])
    ->setSelectionSet(['name', 'body']);
$data = GorillaDash::graphql($query, ['slug' => 'about-us']);

// graphqlWithMeta() also accepts a raw query string, and returns the full cache
// envelope (status: miss | fresh | stale, age in seconds):
$result = GorillaDash::graphqlWithMeta('{ websiteInfo { name } }');
// => ['data' => [...], 'cached_at' => 1718..., 'age' => 0, 'status' => 'miss']

// Per-call overrides (different credentials, or a custom TTL):
$data = GorillaDash::connection(['cache_ttl' => 300])->graphql($query);

// Verify credentials (throws GdRequestException on failure):
GorillaDash::ping();
```

HTTP endpoints
--------------

[](#http-endpoints)

The package registers two routes (both can be disabled or repathed via config — see the table above):

### `POST /graphql`

[](#post-graphql)

A ready-to-use GraphQL endpoint that proxies a `{ query, variables }` body through the SWR cache and returns the full envelope (`data` + cache metadata). Useful for client-side / SSR fetching without writing a controller:

```
curl -X POST https://your-site.test/graphql \
  -H 'Content-Type: application/json' \
  -d '{"query":"{ websiteInfo { name url } }"}'
# => { "data": { "websiteInfo": {...} }, "cached_at": 1718..., "age": 0, "status": "miss" }
```

### Cache-clear webhook

[](#cache-clear-webhook)

GorillaDash calls this when content changes, to flush this site's cache. Point GorillaDash's **"Cache Clear URL"** at `{your-site}/gorilla-dash/clear-cache?key={public_key}`; a request whose `key` matches `public_key` flushes the cache (any other request gets a `404`).

Error handling
--------------

[](#error-handling)

Transport, auth and GraphQL errors throw `GorillaDash\WebsiteSdk\Exceptions\GdRequestException`:

```
use GorillaDash\WebsiteSdk\Exceptions\GdRequestException;
use GraphQL\Query;

try {
    $info = GorillaDash::graphql((new Query('websiteInfo'))->setSelectionSet(['name', 'url']));
} catch (GdRequestException $e) {
    $info = null; // render a fallback; $e->graphqlErrors holds GraphQL error details
}
```

Inertia SSR client sites
------------------------

[](#inertia-ssr-client-sites)

Fetch in the controller and pass the data as Inertia props — the cache keeps it fast and SSR renders it into the initial HTML:

```
use GraphQL\Query;

return Inertia::render('Home', [
    'info' => GorillaDash::graphql(
        (new Query('websiteInfo'))->setSelectionSet(['name', 'url'])
    ),
    'menu' => GorillaDash::graphql(
        (new Query('websiteMenu'))
            ->setArguments(['name' => 'Main Menu'])
            ->setSelectionSet(['name', 'menu_json'])
    ),
]);
```

Testing
-------

[](#testing)

Fake the HTTP layer with Laravel's `Http::fake()` — no real API calls:

```
use GraphQL\Query;

Http::fake([
    'api.gorilladash.com/oauth/token' => Http::response(['access_token' => 'tok', 'expires_in' => 3600]),
    'api.gorilladash.com/graphql' => Http::response(['data' => ['websiteInfo' => ['name' => 'Acme']]]),
]);

expect(GorillaDash::graphql((new Query('websiteInfo'))->setSelectionSet(['name'])))
    ->toBe(['websiteInfo' => ['name' => 'Acme']]);
```

Run the package test suite:

```
composer install
vendor/bin/pest
```

How it works
------------

[](#how-it-works)

```
Your app ──> GorillaDash facade ──> SwrCache ──> (cache hit? serve)
                                       │
                                       └─ miss/stale ─> TokenManager ─> /oauth/token (cached bearer)
                                                         └─> GraphQlTransport ─> POST /graphql

```

- `TokenManager` — exchanges client-credentials for a bearer token and caches it until just before expiry.
- `GraphQlTransport` — sends queries with the bearer token; retries once on a 401 with a fresh token.
- `SwrCache` — the stale-while-revalidate logic; schedules background refreshes via the application's `terminating` callbacks (runs after the response is sent).

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5094008?v=4)[Casper Lai](/maintainers/casperlaitw)[@CasperLaiTW](https://github.com/CasperLaiTW)

---

Top Contributors

[![CasperLaiTW](https://avatars.githubusercontent.com/u/5094008?v=4)](https://github.com/CasperLaiTW "CasperLaiTW (2 commits)")[![wheredidgogogo](https://avatars.githubusercontent.com/u/2225376?v=4)](https://github.com/wheredidgogogo "wheredidgogogo (2 commits)")

---

Tags

laravelsdkgraphqlcachestale-while-revalidateSSRgorilladash

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/gorilladash-laravel-website-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/gorilladash-laravel-website-sdk/health.svg)](https://phpackages.com/packages/gorilladash-laravel-website-sdk)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

43140.3k](/packages/harris21-laravel-fuse)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4923.6k5](/packages/ralphjsmit-laravel-glide)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

2119.7k](/packages/iazaran-smart-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
