{"id":19044201,"url":"https://github.com/sevenecks/laravel-simple-cache","last_synced_at":"2026-05-17T03:04:36.809Z","repository":{"id":62542736,"uuid":"114174856","full_name":"sevenecks/laravel-simple-cache","owner":"sevenecks","description":"Simple wrapper for the Laravel Cache facade that provides namespacing for keys and time to live functionality.","archived":false,"fork":false,"pushed_at":"2018-01-23T20:36:44.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-03T09:42:28.415Z","etag":null,"topics":["caching","facade","laravel","laravel-cache","laravel-package"],"latest_commit_sha":null,"homepage":"https://github.com/SevenEcks/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sevenecks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-13T22:19:48.000Z","updated_at":"2018-06-06T15:10:19.000Z","dependencies_parsed_at":"2022-11-02T16:16:13.091Z","dependency_job_id":null,"html_url":"https://github.com/sevenecks/laravel-simple-cache","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/sevenecks/laravel-simple-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevenecks%2Flaravel-simple-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevenecks%2Flaravel-simple-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevenecks%2Flaravel-simple-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevenecks%2Flaravel-simple-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sevenecks","download_url":"https://codeload.github.com/sevenecks/laravel-simple-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sevenecks%2Flaravel-simple-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283966764,"owners_count":26924587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-12T02:00:06.336Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","facade","laravel","laravel-cache","laravel-package"],"created_at":"2024-11-08T22:45:10.878Z","updated_at":"2025-11-12T03:01:43.245Z","avatar_url":"https://github.com/sevenecks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Installation\n\nVia Composer\n\n```bash\ncomposer require sevenecks/laravel-simple-cache\n```\n\n## Usage\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse SevenEcks\\LaravelSimpleCache\\SimpleCache;\n\nclass PageController extends Controller\n{\n    /**\n     * Gets the contact page from cache or renders it and saves to cache \n     * before returning\n     *\n     * @return string view\n     */\n    public function contact()\n    {\n        $view_name = 'contact';\n        // check if we have a cached view\n        if (!($view_content = SimpleCache::getCached($view_name))) {\n            $view_content = view($view_name);\n            // now let's cache our new view\n            SimpleCache::setCache($view_name, $view_content-\u003erender());\n        }\n        // return the view either from cache or the newly created one\n        return $view_content;\n    }\n}\n```\n\n## Caching CSRF Tokens in Laravel\n\nIn some cases you may have forms on your pages that need a CSRF token. If you cache a page with a CSRF token on it, the form won't work (or won't work for anyone but you). There is a solution to this that doesn't involve partial page caching.\n\nDon't cache an actual CSRF token. Cache a placeholder and then replace it after you've either rendered your view content or pulled the already rendered content from the cache.\n\nFor example, if you have a Blade template that looks like this:\n\n```html\n\u003c!-- CSRF Token --\u003e\n\u003cmeta name=\"csrf-token\" content=\"{{ csrf_token() }}\"\u003e\n```\n\nYou would replace the CSRF token with some placeholder text.\n\n```html\n\u003c!-- CSRF Token --\u003e\n\u003cmeta name=\"csrf-token\" content=\"xxxxxxxxxxxxxx\"\u003e\n```\n\nNext, you would update your caching code to look something like this:\n\n```php\npublic function contact()\n{\n    $view_name = 'contact';\n    // check if we have a cached view\n    if (!($view_content = SimpleCache::getCached($view_name))) {\n        $view_content = view($view_name);\n        // now let's cache our new view\n        SimpleCache::setCache($view_name, $view_content-\u003erender());\n    }\n    // add in the csrf_token() post render/cache\n    $view_content = str_replace('xxxxxxxxxxxxxx', csrf_token(), $view_content);\n    // return the view either from cache or the newly created one\n    return $view_content;\n}\n```\n\n## API\n\n```php\n // prefix for the cache key to namespace it\npublic static $cache_key_prefix = 'simple-cache-';\n\n// text to tag the cache with by default\npublic static $cache_tag = '\u003c!-- cache --\u003e';\n\n/**\n * Returns cached item by key if caching is enabled. If $tag_cached_content is\n * true then the the $cache_tag will be applied to the end of the content after \n * it is pulled from the cache.\n *\n * @param  string $cache_key\n * @return mixed false if cache is disabled or not present, string if it exists.\n */\npublic static function getCached(string $cache_key, bool $tag_cached_content = true)\n\n/**\n * Concatinates the prefix plus dash with suffix to create the cache key\n * namespace.\n *\n * @param  string $prefix\n * @param  string $suffix\n * @return string\n */\npublic static function buildCacheKey(string $prefix, string $suffix = '')\n\n/**\n * Overwrite the static cache key prefix string with a user\n * provided string for customization purporses.\n *\n * @param string $new_prefix\n * @return none\n */\npublic static function setCacheKeyPrefix(string $new_prefix)\n\n/**\n * Get the current $cache_key_prefix variable\n *\n * @return string\n */\npublic static function getCacheKeyPrefix()\n\n/**\n * Overwrite the static cache tag string with a user\n * provided string for customization purposes.\n *\n * @param string $new_tag\n * @return none\n */\npublic static function setCacheTag(string $new_tag)\n\n/**\n * Get the current $cache_tag static varible\n *\n * @return string\n */\npublic static function getCacheTag()\n\n/**\n * Sets the cached content. $minutes_to_live set to -1 will live forever.\n *\n * @param  string $cache_key\n * @param  string $content\n * @param  integer $minutes_to_live = -1\n * @return mixed\n */\npublic static function setCache(string $cache_key, string $content, int $minutes_to_live = -1)\n\n/**\n * Clear the entire cache\n *\n * @return none\n */\npublic static function clearCache()\n```\n\nNow your application should function normally, while maintaining the benefits of caching.\n\n## Change Log\nPlease see [Change Log](CHANGELOG.md) for more information.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsevenecks%2Flaravel-simple-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsevenecks%2Flaravel-simple-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsevenecks%2Flaravel-simple-cache/lists"}