PHPackages                             scottchiefbaker/cache\_sqlite - 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. [Database &amp; ORM](/categories/database)
4. /
5. scottchiefbaker/cache\_sqlite

ActiveLibrary[Database &amp; ORM](/categories/database)

scottchiefbaker/cache\_sqlite
=============================

PHP object caching system with a SQLite backend store and automatic content expiration. Cache is stored using a SQLite database and persists on disk.

v0.6(1mo ago)21MITPHPPHP &gt;=8.0

Since May 8Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/scottchiefbaker/php-sqlite-cache)[ Packagist](https://packagist.org/packages/scottchiefbaker/cache_sqlite)[ Docs](https://github.com/scottchiefbaker/php-sqlite-cache)[ RSS](/packages/scottchiefbaker-cache-sqlite/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

🧰 PHP SQLite object cache
=========================

[](#-php-sqlite-object-cache)

PHP object caching system with a SQLite backend store and automatic content expiration. Cache is stored using a SQLite database and persists on disk.

🛠️ Requirements
---------------

[](#️-requirements)

- PHP 8.0+
- PDO functions in PHP
- SQLite functions in PHP
- JSON functions in PHP

🔍 Optional components
---------------------

[](#-optional-components)

- igbinary
- msgpack

If either **igbinary** or **msgpack** functions are available we will automatically use them as the serialization storage method in the database. If neither are available we fall back to JSON.

✨ Usage
-------

[](#-usage)

```
require("/path/to/dir/cache.class.php");

$opts = ["db_file" => "/var/tmp/mycache.sqlite"];
$cache = new \Scottchiefbaker\Cache\Sqlite($opts);

// Store an item
$key     = "cust:123";
$data    = ['name' => 'Jason Doolis', 'age' => 13, 'animal' => 'kitten'];
$expires = time() + 3600;

$ok = $cache->set($key, $data, $expires);

// Fetch an item
$data = $cache->get($key);
```

🎯 Methods
---------

[](#-methods)

### get($key)

[](#getkey)

Returns stored object.

### set($key, $object, $expire\_time)

[](#setkey-object-expire_time)

Store an object in cache. Returns status of storage.

### delete($key)

[](#deletekey)

Remove an item from cache. Returns status of deletion.

### cached\_item\_count()

[](#cached_item_count)

Return the number of active items in the cache.

### cached\_item\_keys()

[](#cached_item_keys)

Return array of all the active items in the cache.

### remove\_expired\_entries($vacuum\_db)

[](#remove_expired_entriesvacuum_db)

Remove all expired items from cache. If `$vacuum_db` is set, the DB will be vacuumed after removal.

### empty\_cache()

[](#empty_cache)

Remove **all** items from the cache.

🧹 Cleanup
---------

[](#-cleanup)

Over time objects will be added and deleted from the cache. This *may* create database fragmentation. It might be a good idea to `VACUUM` the DB every so often. We have provided a method to do this:

```
// Remove all expired entries and defragment the database
$vacuum = true;
$ok     = $cache->remove_expired_entries($vacuum);
```

🌎 Real World Example
--------------------

[](#-real-world-example)

```
function get_slow_data($id) {
	global $cache;

	$ckey = "item:$id";
	$data = $cache->get($ckey);

	if ($data) { return $data; }

	// Not found in cache go get the data the slow way
	$data = my_slow_data_function($id);

	// Store the data in the cache for two hours
	$ok = $cache->set($ckey, $data, time() + 7200);

	return $ret;
}
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9abab1acc5a8df8723cc365fc7cbc437bb9844fd9f0b9d0a8950925b1ae2ff4d?d=identicon)[scottchiefbaker](/maintainers/scottchiefbaker)

---

Top Contributors

[![scottchiefbaker](https://avatars.githubusercontent.com/u/3429760?v=4)](https://github.com/scottchiefbaker "scottchiefbaker (43 commits)")

---

Tags

sqliteobjectcachecachingSimplemsgpackigbinary

### Embed Badge

![Health badge](/badges/scottchiefbaker-cache-sqlite/health.svg)

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

###  Alternatives

[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114546.3k6](/packages/apix-cache)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.5k5.2M136](/packages/phpfastcache-phpfastcache)[matthiasmullie/scrapbook

Scrapbook is a PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APCu, SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

3222.7M41](/packages/matthiasmullie-scrapbook)[nette/caching

⏱ Nette Caching: library with easy-to-use API and many cache backends.

43619.1M389](/packages/nette-caching)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592452.8k2](/packages/spiritix-lada-cache)[ymigval/laravel-model-cache

Laravel package for caching Eloquent model queries

7955.4k4](/packages/ymigval-laravel-model-cache)

PHPackages © 2026

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