# wpide/3.5.9/App/Services/Transient/Transient.php

WPIDE – File Manager &amp; Code Editor, version 3.5.9. 60 lines.

- Page: https://pluginprobe.com/plugins/wpide/3.5.9/code/App/Services/Transient/Transient.php
- Raw: https://pluginprobe.com/plugins/wpide/3.5.9/raw/App/Services/Transient/Transient.php
- Modified: 2022-07-30T22:45:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpide/3.5.9/code/App/Services/Transient/Transient.php#L10-L20`.

```php
<?php
namespace WPIDE\App\Services\Transient;

use WPIDE\App\Services\Service;

class Transient implements Service
{

    protected $prefix;

    public function init(array $config = [])
    {

        $this->prefix = !empty($config['prefix']) ? $config['prefix'] : '';
    }

    public function set($key, $val, $expiration = YEAR_IN_SECONDS): bool
    {

        return set_transient( $this->prefix.$key, $val, $expiration );
    }

    public function get($key, $default = null) {

        $value = get_transient( $this->prefix.$key );

        if($value === false) {
            return $default;
        }

        return $value;
    }

    public function delete($key): bool
    {

        return delete_transient( $this->prefix.$key );
    }

    public function exists($key): bool
    {

        return $this->get( $key ) !== false;
    }

    public function result($key, callable $callback, $expiration = YEAR_IN_SECONDS) {

        $cached = $this->get($key);

        if($cached === false || !empty($_GET['nocache'])) {

            $cached = $callback();

            $this->set($key, $cached, $expiration);
        }

        return $cached;
    }

}
```
