Coder Social home page Coder Social logo

Wrong ttl after normalizeTtl about cache-db HOT 7 CLOSED

yiisoft avatar yiisoft commented on June 1, 2024
Wrong ttl after normalizeTtl

from cache-db.

Comments (7)

darkdef avatar darkdef commented on June 1, 2024

I think, with TTL equal 0 - TTL_EXPIRED it's correct behaviour. If you need TTL_INFINITY - just use NULL in Set method

from cache-db.

terabytesoftw avatar terabytesoftw commented on June 1, 2024

Configuration in /config/db.php:

<?php

declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Yiisoft\Cache\Db\DbCache;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Pgsql\Connection;

/** @var array $params */

return [
    DbCache::class => static function (ContainerInterface $container) {
        return new DbCache($container->get(ConnectionInterface::class), 'test-table');
    },

    ConnectionInterface::class => [
        'class' => Connection::class,
        '__construct()' => [
            'dsn' => 'pgsql:host=127.0.0.1;dbname=scrutinizer;port=5432',
        ],
        'setUsername()' => ['scrutinizer'],
        'setPassword()' => ['scrutinizer'],
    ],
];

from cache-db.

Gerych1984 avatar Gerych1984 commented on June 1, 2024

I think, with TTL equal 0 - TTL_EXPIRED it's correct behaviour. If you need TTL_INFINITY - just use NULL in Set method

I understood that. But is not logical for me. I see that INFINITY const = 0, i used 0 (like and yii2), and after i find method in source and reed it i see that it must be used null instead

from cache-db.

terabytesoftw avatar terabytesoftw commented on June 1, 2024

Creo que, con TTL igual a 0 - TTL_EXPIRED es un comportamiento correcto. Si necesita TTL_INFINITY, simplemente use NULL en el método Set

Lo entendí. Pero no es lógico para mí. Veo que INFINITY const = 0, usé 0 (like y yii2), y después de encontrar el método en source y reed it veo que debe usarse null en su lugar

If it is correct if you want the cache to be infinite, just don't set ttl, the package is still missing the documentation, soon we will do it completely.

from cache-db.

Gerych1984 avatar Gerych1984 commented on June 1, 2024

Configuration in /config/db.php:

<?php

declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Yiisoft\Cache\Db\DbCache;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Pgsql\Connection;

/** @var array $params */

return [
    DbCache::class => static function (ContainerInterface $container) {
        return new DbCache($container->get(ConnectionInterface::class), 'test-table');
    },

    ConnectionInterface::class => [
        'class' => Connection::class,
        '__construct()' => [
            'dsn' => 'pgsql:host=127.0.0.1;dbname=scrutinizer;port=5432',
        ],
        'setUsername()' => ['scrutinizer'],
        'setPassword()' => ['scrutinizer'],
    ],
];

No, I try it few hours and now I have default config. But its work after I replace 0 with null )

from cache-db.

terabytesoftw avatar terabytesoftw commented on June 1, 2024
$dbCache->set('test', 'test-me', 0); //show null
$dbCache->set('test1', 'test-me-1'); //show test-me-1
$dbCache->set('test2', 'test-me-2', 3600); // show test-me-2

https://www.php-fig.org/psr/psr-16/

If a negative or zero TTL is provided, the item MUST be deleted from the cache if it exists, as it is expired already.

from cache-db.

Gerych1984 avatar Gerych1984 commented on June 1, 2024
$dbCache->set('test', 'test-me', 0); //show null
$dbCache->set('test1', 'test-me-1'); //show test-me-1
$dbCache->set('test2', 'test-me-2', 3600); // show test-me-2

https://www.php-fig.org/psr/psr-16/

If a negative or zero TTL is provided, the item MUST be deleted from the cache if it exists, as it is expired already.

It's very confused - we have infinity constant with zero value. But for used they, we must pass null

from cache-db.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.