PHPackages                             erikbooij/cache-scheduler - 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. erikbooij/cache-scheduler

ActiveLibrary[Caching](/categories/caching)

erikbooij/cache-scheduler
=========================

A simple way to get the most out of your cache TTL.

1.0.0(7y ago)322MITPHPPHP ^7.1

Since Feb 24Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ErikBooij/php-cache-scheduler)[ Packagist](https://packagist.org/packages/erikbooij/cache-scheduler)[ RSS](/packages/erikbooij-cache-scheduler/feed)WikiDiscussions master Synced 2w ago

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

This *Cache Scheduler* is a library that allows you to vary your cache TTLs according to a self defined schedule. I've written [a little blog post on why you might want to consider that](https://dev.to/erikbooij/getting-the-most-out-of-server-side-caching-35o7).

Usage is simple:

1. install it with Composer:

    ```
    $ composer require erikbooij/cache-scheduler
    ```
2. Create a schedule and scheduler:

    ```
    $schedule = (new Schedule)
        ->requireUpToDateDataFrom(Schedule::MON, 8, 0)
        ->allowStaleDataFrom(Schedule::MON, 17, 30)
        ->requireUpToDateDataFrom(Schedule::TUE, 8, 0)
        ->allowStaleDataFrom(Schedule::TUE, 17, 30)
        ->requireUpToDateDataFrom(Schedule::WED, 8, 0)
        ->allowStaleDataFrom(Schedule::WED, 17, 30)
        ->requireUpToDateDataFrom(Schedule::THU, 8, 0)
        ->allowStaleDataFrom(Schedule::THU, 17, 30)
        ->requireUpToDateDataFrom(Schedule::FRI, 8, 0)
        ->allowStaleDataFrom(Schedule::FRI, 17, 30);

    // Create the scheduler, passing it a SystemClock instance to interface with system time
    $scheduler = (new Scheduler(new SystemClock))
        ->setSchedule($schedule)
        ->setExpirationSpread(ExpirationSpread::minutes(30));
    ```
3. Use the scheduler to determine the allowed lifespan of your item in cache:

    ```
    $cache->set('cache-key', 'cache-value', $scheduler->calculateTimeToLive(3600));
    ```

The number passed as the first argument to `->calculateTimeToLive()` is the cache TTL if your data is currently require to be up-to-date (the default TTL).

Instead of attaching the schedule and expiration spread to the scheduler as in the example, you can also pass that as the second and third argument respectively to `->calculateTimeToLive()`. If you use both, the method arguments will override the values attached to the scheduler.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

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

2682d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5747956?v=4)[Erik Booij](/maintainers/ErikBooij)[@ErikBooij](https://github.com/ErikBooij)

---

Top Contributors

[![ErikBooij](https://avatars.githubusercontent.com/u/5747956?v=4)](https://github.com/ErikBooij "ErikBooij (9 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/erikbooij-cache-scheduler/health.svg)

```
[![Health](https://phpackages.com/badges/erikbooij-cache-scheduler/health.svg)](https://phpackages.com/packages/erikbooij-cache-scheduler)
```

###  Alternatives

[beryllium/cachebundle

Provides an interface to Memcache for Symfony2 applications

32136.0k](/packages/beryllium-cachebundle)

PHPackages © 2026

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