PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.36k stars 452 forks source link

How to get different Buckets without "Calling many times warning" #659

Closed Yamakasi closed 5 years ago

Yamakasi commented 5 years ago

Configuration (optional) Not related

My question

I have my Cache instance loading pretty at the top of my application or seperated in the objects I call but at the moment I stumble into the instance is get to much in some class/object. Actually I do wonder how to debug it best but also, how to switch between Buckets in your app without falling into this message all the time ?

/edit 1 I also came up to this kind of solution and see it as a confirmation as solution but isn't it application wise not more "heavy" to get an instance all the time ?

/edit 2 It seems it doesn't really create a new instance, the complains still exist in the log. The f (static::$objInstance === null) { ... } does actually the same thing as checking if the class is already loaded, so it keeps using the known/loaded instance.

/edit 3 The only solution I found is do some comparisons and clearInstances() and start over again with the right config. This works good but I don't understand the comment about using that function only internally ?? If it fits the purpose when there seems no other way ??

Geolim4 commented 5 years ago

Hello,

Just store the instance statically and the issue will goes away. Or I may not fully understood your issue since your English looks limited (no offense).

Yamakasi commented 5 years ago

Hi,

It could have been the language barrier or the late hour of the day ;) (both I guess)

In /edit 2 I clearly forgot to add the link:

https://github.com/PHPSocialNetwork/phpfastcache/issues/585#issuecomment-390434268

(due the hour of the day ;))

Geolim4 commented 5 years ago

Like I said previously, just store the instance statically and the issue will goes away.

By design you're not supposed to re-instantiate the poll with the same config multiple times.

Yamakasi commented 5 years ago

I know and understand that, I thought to see the same happening when doing multiple staticly with the same config while testing.

Yamakasi commented 5 years ago

OK, edit on this update, it seems that the check if the driver is loaded is a little bit wacky if you ask me. with instanceof, is_a((), it all doesn't matter if you create a session class put all functions for your own need in and load that one, even as instance, not at all.

Tips/examples are welcome!

Geolim4 commented 5 years ago

This is because the library is psr6 compliant: https://www.php-fig.org/psr/psr-6/

Please read the documentation and readme.

On Tue, Dec 11, 2018, 4:52 AM Yamakasi <notifications@github.com wrote:

Also, what I don't get is that when I call an instance of my Cachehandler the ->get() function is not avaiable anymore but->getItem() is.

This confused me because when initiating my class I can use the simple ->get(), ->set() functions.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/PHPSocialNetwork/phpfastcache/issues/659#issuecomment-446063405, or mute the thread https://github.com/notifications/unsubscribe-auth/ABRTZyQukCcrFOtpAmuac-oGfVRnUgJlks5u3ywJgaJpZM4ZHofG .

Yamakasi commented 5 years ago

I want to update this and I hope you can work on a solution as I think there isa real flaw in phpfastcache.

I have a working instance way, the issue there is, I cannot switch buckets when the instance is in my object, $this->cacheHandler stays $this->cacheHandler with the bucket loaded.

When initiating a new Cache($config, $instanceId) and doing some magic on the connection check in the contruct, etc to check a valid Id, the same too much driver loaded issues start existing as I try to check if the 'Id" was already there... which is not, it's a new one. I want to try to put that part into the getInstance() to see what happens but that is the last option.

You need to be able to switch buckets in your app!

Please come with some more valid examples if you can, most ones are just tests and not showing the real way(s).

Thanks!

Yamakasi commented 5 years ago

Can you please respond on this ? While investigating this it seems you are filling up the items in a cacheInstance and tell the user that getting the driver again is bad practice. I have the feeling that it's a by design library issue as the cache servers and also the clientlibs don't care about it.

I also ask myself, why filling up and keeping data in an instance object when it's not needed anymore ? Cache should be on demand, your lib is doing different.

Please explain, thanks!

Have some good Holidays!

Geolim4 commented 5 years ago

Like I said ,previously, you are wrongly using Phpfastcache, do not instantiate same driver twice or more, and actually tests are greens.

So please read the docs very closely. You are the only one getting troubles with psr-6 functioning.