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

Should unmatched cache() return null? #1870

Closed
MGatner opened this issue Mar 26, 2019 · 4 comments
Closed

Should unmatched cache() return null? #1870

MGatner opened this issue Mar 26, 2019 · 4 comments

Comments

@MGatner
Copy link
Member

MGatner commented Mar 26, 2019

The cache Service accessory for the Caching Library is incredibly helpful and makes for seamless data sourcing among session, input, etc. However, that it doesn't mimic the other wrappers in returning "null" makes for cumbersome extra checks.
I wonder if there was an explicit reason for cache to return "false" (making it impossible to cache anything to 'false')? And if not would that be okay to change?
Ref: https://codeigniter4.github.io/CodeIgniter4/general/common_functions.html#cache

EDIT: wording

@atishhamte
Copy link
Contributor

I guess, it should be null if no data found with associated key passed to maintain the consistency throughout the project

@MGatner
Copy link
Member Author

MGatner commented Mar 28, 2019

Looking into this, it is a bit more complicated as each Cache handler has its own implementation of get() that handle the data differently. I still think this is worth changing, but it might take some help form someone who understands each handler (e.g. what does $this->memcached->get($key) return for missing keys?).

@lonnieezell
Copy link
Member

I don't know that there is a reason for it being different honestly. This and the session drivers were all ported over with very little changes, so I didn't analyze them much. I have no problem with them returning NULL, and that makes sense to make for consistency sake.

Actually, NULL seems to make even more sense given that you could frequently store values of false so how do you know that's different then not there?

But I also don't know the different engines all that well, so would be researching as I went, also.

@MGatner
Copy link
Member Author

MGatner commented Mar 29, 2019

Needing to store false is exactly what brought me to this! I didn’t realize these were direct ports - I’ll do some digging when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants