PHPackages                             vasco-fund/symfony-firestore-cache-adapter - 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. vasco-fund/symfony-firestore-cache-adapter

ActiveLibrary[Caching](/categories/caching)

vasco-fund/symfony-firestore-cache-adapter
==========================================

Symfony Cache adapter for Google Cloud Firestore - Production-ready PSR-6 implementation

1.0.0(5mo ago)0111[1 issues](https://github.com/vasco-fund/symfony-firestore-cache-adapter/issues)[1 PRs](https://github.com/vasco-fund/symfony-firestore-cache-adapter/pulls)MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since Jan 19Pushed 5mo agoCompare

[ Source](https://github.com/vasco-fund/symfony-firestore-cache-adapter)[ Packagist](https://packagist.org/packages/vasco-fund/symfony-firestore-cache-adapter)[ RSS](/packages/vasco-fund-symfony-firestore-cache-adapter/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (13)Versions (2)Used By (0)

Symfony Firestore Cache Adapter
===============================

[](#symfony-firestore-cache-adapter)

[![Build Status](https://github.com/vasco-fund/symfony-firestore-cache-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/vasco-fund/symfony-firestore-cache-adapter/actions/workflows/ci.yml)[![PHPStan Level](https://camo.githubusercontent.com/1bc07920f0d36e55c17e1d38b1caa132cc605f51a82b388c962870b9a747b898/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e737667)](phpstan.neon)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/a14ae9f06be7527af3e32af9a08e4d06cdc671d10ebafde7f02d84f46429294e/68747470733a2f2f706f7365722e707567782e6f72672f766173636f2d66756e642f73796d666f6e792d6669726573746f72652d63616368652d616461707465722f762f737461626c65)](https://packagist.org/packages/vasco-fund/symfony-firestore-cache-adapter)

Production-ready Symfony Cache adapter for Google Cloud Firestore. Perfect for Cloud Run, App Engine, and other stateless GCP environments where filesystem cache is not persistent.

Features
--------

[](#features)

- **PSR-6 compliant** - Implementation of Psr\\Cache\\CacheItemPoolInterface
- **Namespace isolation** - Multi-tenant support with cache namespacing
- **High performance** - Batch operations and optimized Firestore queries
- **Cloud Run optimized** - Works seamlessly with ephemeral containers
- **Flexible client options** - Choose between HTTP client (no extensions required) or Google Cloud SDK (better performance)

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

[](#installation)

```
composer require vasco-fund/symfony-firestore-cache-adapter
```

### Optional: Google Cloud SDK

[](#optional-google-cloud-sdk)

By default, this adapter uses the Firestore REST API via Symfony HTTP Client, which works out of the box without any PHP extensions.

For better performance, you can optionally install the Google Cloud SDK (requires the `grpc` PHP extension):

```
composer require google/cloud-firestore
```

⚠️ You will have to code you own client implementation to use the SDK.

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

[](#requirements)

- PHP 8.2 or higher
- Symfony 7.4 or 8.x
- Google Cloud Firestore credentials
- **Optional**: `grpc` PHP extension (only required if using Google Cloud SDK)

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

[](#configuration)

The adapter supports two Firestore client implementations:

- **HTTP Client** (default) - Uses Symfony HTTP Client, no extensions required

Planned improvements:

- **Google Cloud SDK** - Better performance, requires `grpc` extension

### 1. Basic Configuration (HTTP Client - Default)

[](#1-basic-configuration-http-client---default)

```
# config/packages/cache.yaml
framework:
    cache:
        # Unique name of your app: used to compute stable namespaces for cache keys.
        prefix_seed: your_app_name
        pools:
            app.cache:
                adapter: cache.adapter.firestore

# config/packages/services.yaml
services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    cache.adapter.firestore:
        class: Vasco\FirestoreCache\FirestoreAdapter
        public: true
        arguments:
          -   '%kernel.environment%'
          -   86400 # 24 hours
          -   null
          -   '@Vasco\FirestoreCache\Client\Http\FirestoreHttpClient'
          -   'symfony_cache'
    Vasco\FirestoreCache\Client\Http\FirestoreHttpClient:
        class: Vasco\FirestoreCache\Client\Http\FirestoreHttpClient
        arguments:
            $projectId: '%env(GOOGLE_CLOUD_PROJECT)%'
            $database: firestore_database
```

### Which Client Should I Use?

[](#which-client-should-i-use)

FeatureHTTP Client (Default)Google Cloud SDK**Requirements**None`grpc` PHP extension**Installation**Works out of the box`composer require google/cloud-firestore`**Performance**Good (~20-50ms latency)Better (~10-30ms latency)**Ease of Setup**Very easyMay require extension compilation**Best For**Cloud Run, simple setupsHigh-performance needs**Status**ImplementedPlanned**Recommendation**: Start with HTTP client. Only switch to SDK if you need the extra performance and can install the grpc extension.

Usage Examples
--------------

[](#usage-examples)

### Basic Cache Operations

[](#basic-cache-operations)

```
use Psr\Cache\CacheItemPoolInterface;

class YourService
{
    public function __construct(
        private CacheItemPoolInterface $cache
    ) {}

    public function getData(string $id): array
    {
        $item = $this->cache->getItem('data_' . $id);

        if (!$item->isHit()) {
            $data = $this->fetchDataFromDatabase($id);
            $item->set($data);
            $item->expiresAfter(3600); // 1 hour
            $this->cache->save($item);
        }

        return $item->get();
    }
}
```

Environment Variables
---------------------

[](#environment-variables)

### For HTTP Client

[](#for-http-client)

```
# Required
GOOGLE_CLOUD_PROJECT=your-project-id
```

Performance Considerations
--------------------------

[](#performance-considerations)

### Storage Costs

[](#storage-costs)

- Firestore charges for storage and per document read/write operation
- Use appropriate TTL values to minimize storage
- Consider namespacing for cache isolation

### Latency

[](#latency)

- Firestore adds network latency (~10-50ms), it should not be used as the main cache backend for application requiring high performance
- Use batch operations when possible (implemented internally)
- Consider longer TTL for frequently accessed data

### Best Practices

[](#best-practices)

1. **Set appropriate TTL** - Don't cache forever
2. **Monitor Firestore usage** in GCP Console
3. **Use namespaces** for multi-environment setups

Testing
-------

[](#testing)

### Run Tests

[](#run-tests)

```
composer test
```

### With Coverage

[](#with-coverage)

```
composer test:coverage
```

### With mutation Testing

[](#with-mutation-testing)

```
composer infection
```

### Static Analysis

[](#static-analysis)

```
composer phpstan
```

### Code Style

[](#code-style)

```
composer cs:check
composer cs:fix
```

### Full Quality Assurance

[](#full-quality-assurance)

```
composer qa
```

Firestore Structure
-------------------

[](#firestore-structure)

### Cache Items Collection

[](#cache-items-collection)

```
symfony_cache (collection)
├── {namespace}:{key} (document)
│   ├── value: string (compressed or raw)
│   ├── expiresAt: timestamp
│   ├── version: int
│   └── compressed: bool

```

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Rémi Janot](https://github.com/rjanot)
- [All Contributors](https://github.com/vasco-fund/symfony-firestore-cache-adapter/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Roadmap
-------

[](#roadmap)

- Support for Firestore using gRPC

Alternatives
------------

[](#alternatives)

- **Memcached/Redis on GCP** - Better performance but requires always-up service
- **Symfony's ChainAdapter** - Combine Firestore with APCu for local cache

FAQ
---

[](#faq)

**Q: Why Firestore instead of Redis/Memcached?**A: Firestore is serverless, scales automatically, and works perfectly with Cloud Run's ephemeral containers. No need to manage a separate cache cluster.

**Q: What about costs?**A: Firestore pricing is per storage size and per operation. With compression and proper TTL, costs are typically $5-20/month for small to medium applications.

**Q: Can I use this in production?**A: Yes! This adapter is production-ready with comprehensive tests, strict type checking (PHPStan level 9), and follows Symfony best practices.

**Q: Does it work with Symfony 6?**A: Yes, it supports Symfony 7.4 LTS and Symfony 8.x.

**Q: Do I need the grpc extension?**A: No! By default, the adapter uses Symfony HTTP Client which requires no extensions. You can optionally use the Google Cloud SDK for better performance if you have the grpc extension installed.

**Q: Which client should I use?**A: Start with the HTTP client (default) - it's easier to set up and works everywhere. Switch to the SDK client only if you need the extra performance and can install the grpc extension.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance70

Regular maintenance activity

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

166d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/125596754?v=4)[Remi](/maintainers/remi-vasco)[@remi-vasco](https://github.com/remi-vasco)

---

Top Contributors

[![remi-vasco](https://avatars.githubusercontent.com/u/125596754?v=4)](https://github.com/remi-vasco "remi-vasco (10 commits)")

---

Tags

symfonycachepsr-16psr-6google cloudgcpfirestorecloud run

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vasco-fund-symfony-firestore-cache-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/vasco-fund-symfony-firestore-cache-adapter/health.svg)](https://phpackages.com/packages/vasco-fund-symfony-firestore-cache-adapter)
```

###  Alternatives

[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k373.5M3.3k](/packages/symfony-cache)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M577](/packages/shopware-core)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M739](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M204](/packages/sulu-sulu)

PHPackages © 2026

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