Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't store PageArray or WireCache as array keys in WireCache #775

Open
adrianbj opened this issue Dec 27, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@adrianbj
Copy link

commented Dec 27, 2018

Short description of the issue

If you try to store an array in a WireCache the returned array is broken if you have WireCache or PageArray as keys in the array.

Expected behavior

It should return the array exactly as it is stored.

Actual behavior

Kinda whacky array returned with most data missing.

Optional: Suggestion for a possible fix

The problem is due to this code: https://github.com/processwire/processwire/blob/649d2569abc10bac43e98ca98db474dd3d6603ca/wire/core/WireCache.php#L279-L285

My old workaround was to manually serialize and unserialize the array, but I'd rather it was stored as JSON, so I just switched things so I manually json_encode and then prefix it with a ~ before saving the cache. This prevents the WireCache code from seeing it as JSON so it returns it as a string so I can then get the cache and manually remove the ~ and then json_decode.

The problem is immediately fixed if I remove those referenced lines of code, but I realize that's not a viable solution. Perhaps we could have any option to handle the conversion of arrays to strings ourselves without WireCache trying to do it for us - maybe a new argument when calling save() get() to tell it to leave it to us?

Steps to reproduce the issue

  1. save an standard array to a wireCache with one or both of those keys
  2. get the cache
@ethanbeyer

This comment has been minimized.

Copy link

commented Dec 29, 2018

I've run into this before. Your ~ idea is something I never thought to do. Thanks for the tip. Hope there's a fix for this in the meantime.

@ryancramerdesign

This comment has been minimized.

Copy link
Contributor

commented Apr 29, 2019

I don't think this issue exists anymore but please re-open if you find it still to be an issue. Thanks.

@adrianbj

This comment has been minimized.

Copy link
Author

commented Apr 29, 2019

@ryancramerdesign - the issue still exists - it's just that now you're returning more explicit errors about why it doesn't work.

https://github.com/processwire/processwire/blob/f2dbdb118e0a67814abbe28093c5031d97108385/wire/core/WireCache.php#L421-L424

The ~ hack is still needed.

@netcarver netcarver reopened this Apr 29, 2019

@ryancramerdesign

This comment has been minimized.

Copy link
Contributor

commented Apr 29, 2019

@adrianbj @netcarver PageArray and WireCache are the names of PW core classes and are reserved words here, and this needs to be the case. They are the only reserved words in WireCache, you can use anything else you'd like. The issue before was that it didn't throw an Exception when you tried to use a reserved word, when it should have. That has been corrected, so it now provides the proper exception to prevent use of a reserved word from causing a bigger problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.