{"action":"created","issue":{"url":"https://api.github.com/repos/elkarte/Elkarte/issues/2436","repository_url":"https://api.github.com/repos/elkarte/Elkarte","labels_url":"https://api.github.com/repos/elkarte/Elkarte/issues/2436/labels{/name}","comments_url":"https://api.github.com/repos/elkarte/Elkarte/issues/2436/comments","events_url":"https://api.github.com/repos/elkarte/Elkarte/issues/2436/events","html_url":"https://github.com/elkarte/Elkarte/issues/2436","id":140487826,"number":2436,"title":"Cache::enable","user":{"login":"emanuele45","id":1095308,"avatar_url":"https://avatars.githubusercontent.com/u/1095308?v=3","gravatar_id":"","url":"https://api.github.com/users/emanuele45","html_url":"https://github.com/emanuele45","followers_url":"https://api.github.com/users/emanuele45/followers","following_url":"https://api.github.com/users/emanuele45/following{/other_user}","gists_url":"https://api.github.com/users/emanuele45/gists{/gist_id}","starred_url":"https://api.github.com/users/emanuele45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emanuele45/subscriptions","organizations_url":"https://api.github.com/users/emanuele45/orgs","repos_url":"https://api.github.com/users/emanuele45/repos","events_url":"https://api.github.com/users/emanuele45/events{/privacy}","received_events_url":"https://api.github.com/users/emanuele45/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elkarte/Elkarte/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/elkarte/Elkarte/labels/question","name":"question","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/elkarte/Elkarte/milestones/4","html_url":"https://github.com/elkarte/Elkarte/milestones/1.1%20Beta%201","labels_url":"https://api.github.com/repos/elkarte/Elkarte/milestones/4/labels","id":447100,"number":4,"title":"1.1 Beta 1","description":"","creator":{"login":"eurich","id":1027992,"avatar_url":"https://avatars.githubusercontent.com/u/1027992?v=3","gravatar_id":"","url":"https://api.github.com/users/eurich","html_url":"https://github.com/eurich","followers_url":"https://api.github.com/users/eurich/followers","following_url":"https://api.github.com/users/eurich/following{/other_user}","gists_url":"https://api.github.com/users/eurich/gists{/gist_id}","starred_url":"https://api.github.com/users/eurich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eurich/subscriptions","organizations_url":"https://api.github.com/users/eurich/orgs","repos_url":"https://api.github.com/users/eurich/repos","events_url":"https://api.github.com/users/eurich/events{/privacy}","received_events_url":"https://api.github.com/users/eurich/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":281,"state":"open","created_at":"2013-10-07T08:37:11Z","updated_at":"2016-03-13T14:47:03Z","due_on":"2015-09-06T22:00:00Z","closed_at":null},"comments":4,"created_at":"2016-03-13T13:59:39Z","updated_at":"2016-03-13T16:16:13Z","closed_at":null,"body":"That's more or less for @joshuaadickerson \r\n\r\nthe Cache::enable method simply sets the enabled property to true, but if the cache is not **really** enabled to begin with, the cache object doesn't exist at all, so toggling enable like is done in [Errors.class.php](https://github.com/elkarte/Elkarte/blob/23b10d7177a09acc9fb01d63df4af9e84766e013/sources/Errors.class.php#L566) ends up in a fatal error because the object is null.\r\n\r\nSo, the question is: is enable intended to completely override the settings, or it should respect the settings and just ignore toggling when cache is not enabled?\r\nI'd say the latter because how are we sure the cache is even usable if not properly configured?"},"comment":{"url":"https://api.github.com/repos/elkarte/Elkarte/issues/comments/195988931","html_url":"https://github.com/elkarte/Elkarte/issues/2436#issuecomment-195988931","issue_url":"https://api.github.com/repos/elkarte/Elkarte/issues/2436","id":195988931,"user":{"login":"joshuaadickerson","id":195087,"avatar_url":"https://avatars.githubusercontent.com/u/195087?v=3","gravatar_id":"","url":"https://api.github.com/users/joshuaadickerson","html_url":"https://github.com/joshuaadickerson","followers_url":"https://api.github.com/users/joshuaadickerson/followers","following_url":"https://api.github.com/users/joshuaadickerson/following{/other_user}","gists_url":"https://api.github.com/users/joshuaadickerson/gists{/gist_id}","starred_url":"https://api.github.com/users/joshuaadickerson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshuaadickerson/subscriptions","organizations_url":"https://api.github.com/users/joshuaadickerson/orgs","repos_url":"https://api.github.com/users/joshuaadickerson/repos","events_url":"https://api.github.com/users/joshuaadickerson/events{/privacy}","received_events_url":"https://api.github.com/users/joshuaadickerson/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T16:16:13Z","updated_at":"2016-03-13T16:16:13Z","body":"This is why singetons suck for stuff like this. Here's a scenario: you don't want caching most of the time so you disable caching. It doesn't create the cache object (I don't like how it does it anyway). For one or two things you want to use caching. You enable it. There's no cache object. If you set the cache object, you'll be caching for everything else. Say you want to set different things to cache in different places. Same thing.\r\n\r\nOkay, so the solution is to break the creation of the cache obj out of the constructor first off. That method should be doing a test to see if the class_exists($class, true) to enable the autoloader to find it. Then in enable() it should check if it is enabled and create a new cache object if one doesn't already exist (by calling that new method). That means it needs to hold on to those constructor arguments for later.\r\n\r\nThis would be much easier to just use Stash."}}