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

Cache Duration in Cake 2.x #7

Open
garethellis36 opened this issue Jun 18, 2015 · 3 comments
Open

Cache Duration in Cake 2.x #7

garethellis36 opened this issue Jun 18, 2015 · 3 comments
Labels

Comments

@garethellis36
Copy link

Hi Brian,

I just noticed a bug in your 2.x core.php. It jumped out at me because I had the same bug in my production app until a few months ago!

Line 25:
Configure::write("debug", 0);

Line 334:

// In development mode, caches should expire quickly.
$duration = '+999 days';
if (Configure::read('debug') > 0) {
    $duration = '+10 seconds';
}

Environment overrides are not called until later in the file. Therefore, when the value of debug is checked, it is always zero. As a result, dev environments will have long caches.

I am working on implementing your system into our app at the moment and my solution to this is simply to define Cache.Duration as a configuration key in core-{$env} and move the app override code further up core.php.

@beporter beporter changed the title Bug in Cake 2.x branch Cache Duration in Cake 2.x Jun 18, 2015
@cwbit
Copy link

cwbit commented Jun 18, 2015

Using a configuration key is actually more in line with the newer Cake 3 strategy of app-{$env}, too - so, good call!

@beporter
Copy link
Owner

Yep, Chris beat me to it. I'm working on a commit that demonstrates the modifications to make for Cake 2 to handle this. I'll post when I've pushed it.

@beporter
Copy link
Owner

Okay, so this is indeed another excellent point, and is indeed another example where we need to make Cake 2 more like Cake 3 by moving configs into Configure.

The basic idea is instead of calling Cache::config() in the middle of your core.php file directly, you'll set Configure values first, then after loading env-specific configs, you'll configure the Caches.

I just pushed a commit for the sample Cake 2 app that demonstrates one possible solution: 8367acd

The core of that change is right here. This is a little clunkier than how I handle the Database and Email configs (which have their own classes in which to do the necessary dirty work) but it gets the job done with minimal duplication.

beporter added a commit that referenced this issue Jun 18, 2015
Addresses the question raised in #7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants