PHPackages                             ajimoti/cache-duration - 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. ajimoti/cache-duration

ActiveLibrary[Caching](/categories/caching)

ajimoti/cache-duration
======================

This package provides a more readable way to get time in seconds while caching.

1.1.1(4y ago)253292[2 PRs](https://github.com/ajimoti/cache-duration/pulls)MITPHPPHP ^8.0

Since Jan 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ajimoti/cache-duration)[ Packagist](https://packagist.org/packages/ajimoti/cache-duration)[ Docs](https://github.com/ajimoti/cache-duration)[ GitHub Sponsors](https://github.com/ajimoti)[ RSS](/packages/ajimoti-cache-duration/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (4)Versions (6)Used By (0)

PHP Cache Duration
==================

[](#php-cache-duration)

[![Banner](https://camo.githubusercontent.com/a58a3e5a9821aa60870a4143a71613354343a9f560a338d93a432cb537997377/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f43616368652532304475726174696f6e2532305061636b6167652e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616a696d6f746925324663616368652d6475726174696f6e267061747465726e3d636861726c696542726f776e267374796c653d7374796c655f31266465736372697074696f6e3d412b6d6f72652b7265616461626c652b7761792b746f2b6765742b74696d652b696e2b7365636f6e64732b7768696c652b63616368696e67266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d636c6f636b)](https://camo.githubusercontent.com/a58a3e5a9821aa60870a4143a71613354343a9f560a338d93a432cb537997377/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f43616368652532304475726174696f6e2532305061636b6167652e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616a696d6f746925324663616368652d6475726174696f6e267061747465726e3d636861726c696542726f776e267374796c653d7374796c655f31266465736372697074696f6e3d412b6d6f72652b7265616461626c652b7761792b746f2b6765742b74696d652b696e2b7365636f6e64732b7768696c652b63616368696e67266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d636c6f636b)

Introduction
------------

[](#introduction)

A readable and fluent way to generate PHP cache time.

Built and written by [Ajimoti Ibukun](https://www.linkedin.com/in/ibukun-ajimoti-3420a786/)

Quick Samples
-------------

[](#quick-samples)

Instead of this:

```
$cacheDuration = 25 * 60 * 60; // twenty five hours
Redis::expire($userData, $cacheDuration);
```

You can do this

```
$cacheDuration = Duration::twentyFiveHours(); // returns 25 hours in seconds (25 * 60 * 60)
Redis::expire($userData, $cacheDuration);

// or
$cacheDuration = Duration::hours(25); // returns 25 hours in seconds (25 * 60 * 60)
Redis::expire($userData, $cacheDuration);
```

You can also do this:

```
$cacheDuration = Duration::at('first day of January 2023'); // returns the time difference between the present time and the first of january 2023 in seconds

Redis::expire($userData, $cacheDuration);
```

Requirements
------------

[](#requirements)

- PHP 8.0 or higher

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ajimoti/cache-duration --with-all-dependencies
```

Documentation
-------------

[](#documentation)

After installing the package via composer, import the `Duration` trait inside your class, then you are set.

```
