PHPackages                             phpgt/filecache - 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. phpgt/filecache

ActiveLibrary[Caching](/categories/caching)

phpgt/filecache
===============

 Cache data in local files.

v1.3.0(2mo ago)0998↑446.7%[1 issues](https://github.com/PhpGt/FileCache/issues)[4 PRs](https://github.com/PhpGt/FileCache/pulls)2MITPHPPHP &gt;=8.1CI passing

Since Jul 7Pushed 4w ago1 watchersCompare

[ Source](https://github.com/PhpGt/FileCache)[ Packagist](https://packagist.org/packages/phpgt/filecache)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-filecache/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (10)Versions (18)Used By (2)

Cache data in local files.
==========================

[](#cache-data-in-local-files)

Making expensive operations like HTTP calls or database queries can be minimised by caching the result of the operations in local files. This can improve performance, reduce network usage, and avoid rate limiting, to name some common benefits. This library provides a single function to define where to cache, what to cache, and when to cache. A validity of 1 hour is set by default, if the valid time is not specified.

---

[ ![Build status](https://camo.githubusercontent.com/9ab324886f5f78bd6afc9ccefb73a7d5b2b86f00e31120427a96db2f4894c1d7/68747470733a2f2f62616467652e7374617475732e7068702e67742f66696c6563616368652d6275696c642e737667)](https://github.com/PhpGt/FileCache/actions)[ ![Code quality](https://camo.githubusercontent.com/a96413d9e19685cf39f017ed1f5fa9ed7527145f8de4d89f18c5734fee702d3b/68747470733a2f2f62616467652e7374617475732e7068702e67742f66696c6563616368652d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/FileCache)[ ![Code coverage](https://camo.githubusercontent.com/15eda5c59de386d278ecc62e14184a0fb36a43c9ff04f9dab5ad088703663c52/68747470733a2f2f62616467652e7374617475732e7068702e67742f66696c6563616368652d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/FileCache)[ ![Current version](https://camo.githubusercontent.com/1b09fe42cd1e3feb7ab096d659ad716ca4bc4a833a048d663748b8677ec7455c/68747470733a2f2f62616467652e7374617475732e7068702e67742f66696c6563616368652d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/FileCache)[ ![PHP.Gt/FileCache documentation](https://camo.githubusercontent.com/86e46d49480005ec57ad71d529c9d971999096521efc3e714cfa09fac4b4e43e/68747470733a2f2f62616467652e7374617475732e7068702e67742f66696c6563616368652d646f63732e737667)](http://www.php.gt/filecache)Example usage: get the latitude/longitude of the user's IP address
------------------------------------------------------------------

[](#example-usage-get-the-latitudelongitude-of-the-users-ip-address)

It's an expensive operation to make an HTTP call for every page view, but in this example we want to use a remote service to provide us with the estimated latitude/longitude of the current IP address.

The first time we see the IP address will have to make an HTTP call, but subsequent calls will be able to take advantage of the cache.

```
$ipAddress = $_SERVER["REMOTE_ADDR"];
$fileCache = new GT\FileCache\Cache("/tmp/ip-address-geolocation");

// This function uses file_get_contents to contact the remote server
// at ipinfo.io, a costly operation. We will pass the lookup function
// into the cache, so it is only called when we don't have a fresh result.
$lookup = function()use($ipAddress):string {
	$jsonString = file_get_contents("https://ipinfo.io/$ipAddress");
	$obj = json_decode($jsonString);
	return $obj->loc;
}

$location = $fileCache->get("lat-lon", $lookup);
echo "Your location is: $location";
```

If generating a fresh value fails, throw `GT\FileCache\CacheValueGenerationException`from the callback. The cache will ignore that failure and skip writing a replacement value, which leaves `null` available as a legitimate cached value.

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance91

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 77.3% 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 ~197 days

Recently: every ~252 days

Total

8

Last Release

74d ago

Major Versions

v0.2.0 → v1.0.02023-07-14

### Community

Maintainers

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

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-filecache/health.svg)

```
[![Health](https://phpackages.com/badges/phpgt-filecache/health.svg)](https://phpackages.com/packages/phpgt-filecache)
```

###  Alternatives

[beryllium/cachebundle

Provides an interface to Memcache for Symfony2 applications

33136.2k](/packages/beryllium-cachebundle)

PHPackages © 2026

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