This is more of a code snippet post more than anything, but I just wanted to give a more “thorough” example of how to use Illuminate Cache from Laravel 4 as a standalone. There are a few random snippets out there, but I just want to post some sample code to save some people a few minutes to get up and running right away.
I’ve done a fair mount of research on other caching abstraction libraries out there, and I keep coming back to Laravel’s implementation because of its simplicity and its support for a wide-variety of back-ends (e.g. APC, Memcached, Redis, WinCache, XCache, Filesystem, etc.).
The following snippets will cover using the Illuminate Cache as a standalone for the Filesystem- , APC-, Redis-based (with a password/authentication) cache.
- {
- "require": {
- "illuminate/cache": "4.1.*@dev",
- "illuminate/filesystem": "4.1.*@dev",
- "illuminate/redis": "4.1.*@dev"
- }
- }
- use Illuminate\Cache\CacheManager;
- use Illuminate\Filesystem\Filesystem;
-
- 'files' => new FileSystem(),
- 'cache.driver' => 'file',
- 'cache.path' => '/yourcache/dir',
- 'cache.prefix' => 'somenamespace_'
- )
- );
-
- $cacheManager = new CacheManager($app);
- $cache = $cacheManager->driver();
-
- $em = $cache->get("cachekey");
- #echo "Added to Cache";
- #store some data in the cache for 10 minutes
- $cache->put("cachekey", $val, 10);
- $em = $val;
- }
- use Illuminate\Cache\CacheManager;
-
- 'cache.driver' => 'apc',
- 'cache.prefix' => 'somenamespace_'
- )
- );
-
- $cacheManager = new CacheManager($app);
- $cache = $cacheManager->driver();
-
- $em = $cache->get("cachekey");
- #echo "Added to Cache";
- #store some data in the cache for 10 minutes
- $cache->put("cachekey", $val, 10);
- $em = $val;
- }
- use Illuminate\Cache\CacheManager;
- use Illuminate\Redis\Database as Redis;
-
- 'host' => 'yourserver.com',
- 'port' => 16250,
- 'scheme' => 'tcp',
- ),
- ));
-
- 'redis' => $redis,
- 'cache.driver' => 'redis',
- 'cache.prefix' => 'somenamespace_'
- )
- );
-
- $cacheManager = new CacheManager($app);
- $cache = $cacheManager->driver();
- #authentication is optional depending on your situation
-
- $em = $cache->get("cachekey");
- #echo "Added to Cache";
- #store some data in the cache for 10 minutes
- $cache->put("cachekey", $val, 10);
- $em = $val;
- }
As a caveat this is an **unofficial** way of achieving this as of this article's…
There are many benefits to verify your Business Manager on Facebook; however, it is not…
One issue when adding the Facebook pixel to a Google Tag Manager AMP container is…
When trying to run Puppeteer 1.0 within your Node.JS scripts on an Ubuntu 16.04 box and…
Off the back of this article, there could be some potential improvements to make the…
Before implementing the img tag, the previous article should be reviewed: it discusses some of…