Proposal: retrieve cache key from model instance
dirish opened this issue · 2 comments
dirish commented
Maybe add a getCacheKey()
method to the Rememberable trait?
/**
* Get the unique cache key from the query builder.
*
* @return string
*/
public function getCacheKey()
{
return $this->newBaseQueryBuilder()->getCacheKey();
}
Granted, a query builder instance would have to be instantiated for this method to return an effective value, but it was helpful in one of my projects.
Example:
$model = (new Model)->find(1);
\Cache::forget($model->getCacheKey());
dwightwatson commented
Thanks for this, but I'm not sure adding it to the package would provide value to most developers. Seems like the sort of thing will be fine in a trait or base model in your own project.
dirish commented
Thanks for your feedback.