{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/8642","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/8642/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/8642/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/8642/events","html_url":"https://github.com/yiisoft/yii2/issues/8642","id":84613496,"number":8642,"title":"How to cache a fragment based on last modified date","user":{"login":"thejahweh","id":10514993,"avatar_url":"https://avatars.githubusercontent.com/u/10514993?v=3","gravatar_id":"","url":"https://api.github.com/users/thejahweh","html_url":"https://github.com/thejahweh","followers_url":"https://api.github.com/users/thejahweh/followers","following_url":"https://api.github.com/users/thejahweh/following{/other_user}","gists_url":"https://api.github.com/users/thejahweh/gists{/gist_id}","starred_url":"https://api.github.com/users/thejahweh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejahweh/subscriptions","organizations_url":"https://api.github.com/users/thejahweh/orgs","repos_url":"https://api.github.com/users/thejahweh/repos","events_url":"https://api.github.com/users/thejahweh/events{/privacy}","received_events_url":"https://api.github.com/users/thejahweh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-03T15:09:51Z","updated_at":"2015-06-04T08:58:17Z","closed_at":null,"body":"I just want something like this:\r\n```php\r\n$expiresOnThisValue = date('Y-m-d H:i:s');\r\nif ($this->beginCache('test', ['expiresOnThisValues' => [\r\n\t$expiresOnThisValue\r\n]])) {\r\n\techo $expiresOnThisValue. \"\\n\";\r\n\t$this->endCache();\r\n}\r\n```\r\nSo every time the `$expiresOnThisValue` has changed, the cache expires and the content gets newly loaded :tada:\r\n\r\nI tried to write a dependency class with just a variable which is returned on `generateDependencyData`.\r\n\r\n```php\r\nclass VarDependency extends Dependency\r\n{\r\n\tpublic $var;\r\n\r\n\t/**\r\n\t * @param \\yii\\caching\\Cache $cache\r\n\t * @return mixed\r\n\t * @throws InvalidConfigException\r\n\t */\r\n    protected function generateDependencyData($cache)\r\n    {\r\n        if ($this->var === null) {\r\n            throw new InvalidConfigException('VarDependency::var must be set.');\r\n        }\r\n        return $this->var;\r\n    }\r\n}\r\n```\r\n\r\nMy test was as simple like this:\r\n```php\r\n$expiresOnThisValue = date('Y-m-d H:i:s');\r\nif ($this->beginCache('test', ['dependency' => [\r\n\t'class' => 'VarDependency',\r\n\t'var' => $expiresOnThisValue \r\n]])) {\r\n\techo $expiresOnThisValue . \"\\n\";\r\n\t$this->endCache();\r\n}\r\n```\r\n\r\nBut then I realized, that the dependency class is cached too and does not set the var every time."},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/108793354","html_url":"https://github.com/yiisoft/yii2/issues/8642#issuecomment-108793354","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/8642","id":108793354,"user":{"login":"thejahweh","id":10514993,"avatar_url":"https://avatars.githubusercontent.com/u/10514993?v=3","gravatar_id":"","url":"https://api.github.com/users/thejahweh","html_url":"https://github.com/thejahweh","followers_url":"https://api.github.com/users/thejahweh/followers","following_url":"https://api.github.com/users/thejahweh/following{/other_user}","gists_url":"https://api.github.com/users/thejahweh/gists{/gist_id}","starred_url":"https://api.github.com/users/thejahweh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejahweh/subscriptions","organizations_url":"https://api.github.com/users/thejahweh/orgs","repos_url":"https://api.github.com/users/thejahweh/repos","events_url":"https://api.github.com/users/thejahweh/events{/privacy}","received_events_url":"https://api.github.com/users/thejahweh/received_events","type":"User","site_admin":false},"created_at":"2015-06-04T08:58:17Z","updated_at":"2015-06-04T08:58:17Z","body":"@mdmunir Sorry for that confusion, but its not an expression, its a variable which comes from elsewhere. My explanation with `date('Y-m-d H:i:s')` was just for testing."}}