Comments (10)
Can you please open lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php
Search for:
$tagsItem->set(\array_merge((array)$data, [$item->getKey() => $expTimestamp]))
->expiresAt($item->getExpirationDate());
and replace it with:
$tagsItem->set(\array_merge((array)$data, [$item->getKey() => $expTimestamp]));
if (!$tagsItem->isHit() || $tagsItem->getExpirationDate() < $item->getExpirationDate()) {
$tagsItem->expiresAt($item->getExpirationDate());
}
and tell me if it's working on your side :)
from phpfastcache.
from phpfastcache.
Versions 9.1.3 and 8.1.4 have been released.
Happy caching !
from phpfastcache.
Hello curious contributor !
Since it seems to be your first contribution, make sure that you've been:
- Reading and searching out our WIKI
- Reading and agreed with our Code Of Conduct
- Reading and understood our Coding Guideline
- Reading our README
If everything looks unclear to you, tell us what π
The Phpfastcache Team
from phpfastcache.
Hello,
I'm not sure how you get this behavior since the cache already benefits from the cache item with the longest date:
https://github.com/PHPSocialNetwork/phpfastcache/blob/master/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php#L430
Also the tags are tested against this behavior too:
https://github.com/PHPSocialNetwork/phpfastcache/blob/master/tests/ItemTags.test.php
from phpfastcache.
Hello,
I'm not sure how you get this behavior since the cache already benefits from the cache item with the longest date: https://github.com/PHPSocialNetwork/phpfastcache/blob/master/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php#L430
Also the tags are tested against this behavior too: https://github.com/PHPSocialNetwork/phpfastcache/blob/master/tests/ItemTags.test.php
Hey Geo,
If you have multiple keys which have the same tag name and one key gets expired, all keys with the same tag name will be not be displayed anymore (even if they have been not expired) when using getItemsByTag(). This bug doesn't occour if the keys have different tag names. It also doesn't matter if you add just one tag or multiple. As long as one tag gets expired, all other keys with the same tags are gone as well.
In the code example you can see that key_1 getting removed at the same time of key_2, because key_2 getting expired after 5 seconds, while key_1 should have still 5 seconds to live. The cache item key_1 is still there in the pool but cannot longer be called with getItemsByTag().
Simple test:
// instance
$InstanceCache = CacheManager::getInstance('memcached', new Config([
'host' =>'127.0.0.1',
'port' => 11211,
// 'sasl_user' => false, // optional
// 'sasl_password' => false // optional
]));
// key_1
$CachedString1 = $InstanceCache->getItem("key_1");
if (is_null($CachedString1->get())) {
$CachedString1->set("data1")->expiresAfter(10);
$CachedString1->addTag("query");
$InstanceCache->save($CachedString1);
}
// key_2
$CachedString2 = $InstanceCache->getItem("key_2");
if (is_null($CachedString2->get())) {
$CachedString2->set("data2")->expiresAfter(5);
$CachedString2->addTag("query");
$InstanceCache->save($CachedString2);
}
// application layer
$keys = $InstanceCache->getItemsByTag("query");
$aCacheObjects = null;
foreach ($keys as $key) {
$oCacheItem = new stdClass();
$oCacheItem->key = $key->getKey();
$oCacheItem->ttl = $key->getTtl();
$oCacheItem->tags = $key->getTags();
$aCacheObjects[] = $oCacheItem;
}
// render
echo "<pre>";
print_r($aCacheObjects);
echo "</pre>";
from phpfastcache.
Interesting, if you set the 5 sec key first then the 10 sec, the result are valid.
By your example, you does the opposite and there's, indeed an issue.
from phpfastcache.
That's why I doubted it first, because my tests are doing the first use case, not yours. I'm investigating.
from phpfastcache.
I have replaced the code and it works perfectly now. Thank you very much for your quick help, I really appreciate it! :)
from phpfastcache.
I will make an anti-regression test as well, since this behavior was difficult to catch without your specific case.
from phpfastcache.
Related Issues (20)
- Memcached driver compress_data cache miss HOT 4
- Config('path') - Can't declare path from the parent directory of index file directory. HOT 6
- Installation fails: 'Fatal error: Uncaught Error: Class "CacheManager" not found ...' HOT 3
- CanΒ΄t retrieve phpfastcache 9.1.3 thru composer HOT 7
- Saving an item that is already in the pool after its expiration time fails HOT 13
- 2 million data cache? HOT 5
- Storing and retrieving mysql result arrays using Psr16Adapter HOT 4
- Deleting cache by tag without loading all its cache HOT 3
- cache not clearing manually in html HOT 2
- Disable 'securityKey' and adapter directory. HOT 9
- Cache clear() not working with Redis, getItem() still returns data HOT 2
- How to use memcache on v8 ? HOT 3
- Support custom native RedisCluster client HOT 9
- TypeError Phpfastcache\Drivers\Files\Driver::driverRead(): Return value must be of type ?array, bool returned HOT 13
- Memory size exhausted by deleting by Tags HOT 10
- Save - Inside workerman event threads Save() throws fopen() error HOT 4
- Redis will only scan 9999 keys in getAllItems HOT 3
- redis client side cache at php level HOT 4
- Performance differences between drivers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpfastcache.