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.2.0(10mo ago)0633↓50%[1 PRs](https://github.com/PhpGt/FileCache/pulls)1MITPHPPHP &gt;=8.1CI passing

Since Jul 7Pushed 1mo 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 1mo ago

READMEChangelog (7)Dependencies (5)Versions (12)Used By (1)

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";
```

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

44

—

FairBetter than 92% of packages

Maintenance73

Regular maintenance activity

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 72.2% 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 ~183 days

Recently: every ~255 days

Total

7

Last Release

314d 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 (13 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

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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