DEV Community

Cover image for Simple caching class for your PHP projects
alexdodonov
alexdodonov

Posted on • Edited on

4 2

Simple caching class for your PHP projects

Intro

Mezon provides simple cache class. Wich will help you to test how caching will affect performance of your code. If the performance will be boosted, then you can implement more complex solutions for caching.

Installation

Just print in console

composer require mezon/cache
Enter fullscreen mode Exit fullscreen mode

And that's all )

How to use?

First of all we need to create single instance of cache ("singleton" pattern is used):

$cache = Cache::getInstance();
Enter fullscreen mode Exit fullscreen mode

Then we can add data to cache:

$cache->set('key', 'data to be stored');
Enter fullscreen mode Exit fullscreen mode

After all data was added you need to store it to be able using it within other requests.

$cache->flush();
Enter fullscreen mode Exit fullscreen mode

And then you can check if the key exists:

var_dump($cache->exists('key')); // bool(true)
var_dump($cache->exists('unexisting-key')); // bool(false)
Enter fullscreen mode Exit fullscreen mode

And then you can fetch data by it's key:

var_dump($cache->get('key')); // string('data to be stored')
Enter fullscreen mode Exit fullscreen mode

That's all for now )

Learn more

More information can be found here:

Mezon Framework
Twitter

It will be great if you will contribute something to this project. Documentation, sharing the project in your social media, bug fixing, refactoring, or even submitting issue with question or feature request. Thanks anyway )

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay