2017 © Pedro Peláez
 

library file-cache

Minimal PSR-16 cache-implementation

image

kodus/file-cache

Minimal PSR-16 cache-implementation

  • Friday, January 12, 2018
  • by mindplay.dk
  • Repository
  • 5 Watchers
  • 18 Stars
  • 5,277 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 5 Versions
  • 22 % Grown

The README.md

kodus/file-cache

PHP Version Build Status Code Coverage Scrutinizer Code Quality, (*1)

This library provides a minimal PSR-16 cache-implementation backed by simple file-system storage., (*2)

This can be used to provide working, lightweight bootstrapping when you want to ship a project that works out of the box, but doesn't depend on an awesome, full-blown caching-framework., (*3)

Strategy

Files are stored in a specified cache-folder, with two levels of sub-folders to avoid file-system limitations on the number of files per folder. (This will probably work okay for entry-numbers in the tens of thousands - if you're storing cache-entries in the millions, you should not be using a file-based cache.), (*4)

To reduce storage overhead and speed up expiration time-checks, the file modification time will be set in the future. (The file creation timestamp will reflect the time the file was actually created.), (*5)

Usage

Please refer to the PSR-16 spec for the API description., (*6)

Security

In a production setting, consider specifying appropriate $dir_mode and $file_mode constructor-arguments for your hosting environment - the defaults are a typical choice, but you may be able to tighten permissions on your system, if needed., (*7)

Garbage Collection

Because this is a file-based cache, you do need to think about garbage-collection as it relates to your use-case., (*8)

This cache-implementation does not do any automatic garbage-collection on-the-fly, because this would periodically block a user-request, and garbage-collection across a file-system isn't very fast., (*9)

A public method cleanExpired() will flush expired entries - depending on your use-case, consider these options:, (*10)

  1. For cache-entries with non-dynamic keys (e.g. based on primary keys, URLs, etc. of user-managed data) you likely don't need garbage-collection. Manually clearing the folder once a year or so might suffice., (*11)

  2. For cache-entries with dynamic keys (such as Session IDs, or other random or pseudo-random keys) you should set up a cron-job to call the cleanExpired() method periodically, say, once per day., (*12)

For cache-entries with dynamic keys in the millions, as mentioned, you probably don't want a file-based cache., (*13)

The Versions

12/01 2018

dev-master

9999999-dev

Minimal PSR-16 cache-implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Pedersen

08/02 2017

1.1.0

1.1.0.0

Minimal PSR-16 cache-implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

07/02 2017

1.0.0

1.0.0.0

Minimal PSR-16 cache-implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

28/12 2016

0.1.1

0.1.1.0

Minimal PSR-16 cache-implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

0.1.0

0.1.0.0

Minimal PSR-16 cache-implementation

  Sources   Download

MIT

The Requires

 

The Development Requires