Laravel 5.6 Redis as dependency injection - laravel

have been searching through the documentation but to no avail... How should I inject Redis cache through Dependency injection instead of using the Redis facade?

You can find all underlying classes in https://laravel.com/docs/5.5/facades#facade-class-reference. For Redis, it's \Illuminate\Redis\RedisManager. But for caching, I recommend using the default cache driver \Illuminate\Contracts\Cache\Factory because Laravel will namespace the keys behind the scene. If redis isn't the default cache driver, you may specify the store like this:
$cache->store('redis')->get('foo');

Related

Spring(boot)-redis caching- does it need repository creation?

I would like to ask a question about the spring cache annotation and repository creation.
I am trying to cache my values in redis using the Spring boot.
(I have a value, if it is not in cache, I need to cache it, if it is in cache, I need to get it from there)
I have seen a couple of tutorials on line, some using the cache annotations and others simulating the cache repository. (maybe they do not exclude each other, this is my question about)
Here are some of the tutorials that I have read:
Cache annotation tips
Caching Data using Redis
Intro to Redis with Spring Boot
Spring Boot Redis cache
Some of the above use the #Cacheable, #CachePut and #CacheEvict annotations:
#CachePut(value = 'user', key = "#id")
#CacheEvict(value = 'user', key = "#id")
and prefix the supposed-to-be-stored class with the following annotation:
#RedisHash("balance")
They also extend the JPA or CrudRepository. The 3rd one one, however, creates its own repository.
My question is:
If I used the above annotations (#Cacheable, #CachePut and #CacheEvict) should I create a repository for the class objects I am interested in storing by extending the CrudRepository?
Or does spring create it automatically when using the above annotation and manage it automatically?
An if you extend the CrudRepository yourself, how would you retrieve the items by key from Redis?
Thanks
No this is not needed. Notice that the third link does not mention caching up front. There are two projects , spring cache with a redis cache provider and spring data redis. The third link is talking about the larger and more general use case. Spring data redis is meant to support redis as a full fledged persistence layer. However you are certainly free to only use redis as a caching layer. In this case you do not need to do anything nor should you besides using the normal annotations

Accessing the objects currently in Hazelcast Cache in Spring Boot

I want to access all the object present in Hazelcast cache through the cache manager and check them. How do I do it?
After autowiring the cacheManager, what needs to be done next?
Read the documentation here: http://docs.hazelcast.org/docs/3.10/manual/html-single/index.html#hazelcast-jcache
You can use standard get or getAll methods.
Alternatively, use IMap and you can run queries.

Custom Cache Implementation in Ignite

I had a small query over Apache Ignite. Can we have a custom implementation of cache in to store the in-memory state? & where can we plugin the custom implementation.
For eg,
Currently, by default we have IgniteCache for cache management. Can we have something like MyCache for management of cache with the method signatures being the same just the storage technique being different?
Thank you.

How to use cache writer and cache loader in case of Ehcache server

I have used cache-as-sor usage pattern of Ehcache in my web application. now i want to use ehcahe as separate application so i have used cache server. so how to use cache writer and cache loader in case of ehcache server.
In short i want to use method like cache.getWithLoader() and cache.putWithWriter().
As the cache server does not expose these methods, you may be able to handle this by configuring Ehcache in the cache server to use decorated caches that would transform standard get and put into calling into getWithLoader and putWithWriter instead.

Using Redis with Laravel: Do I use the Cache driver, or the Redis class?

I was looking at the Laravel docs and I see a cache driver and a redis class. Looking at the cache class it seems like I could just use this to store things in Redis as I just change which driver I am using for caching to the already added Redis driver. However there is also a separate Redis class. Why is there a separate redis class? If the cache class can do the same thing and allow me to also swap which driver I use if ever needed, what reason is there to use the Redis class?
Maybe I am missing something here but I am just confused which one I want to use to store key's and data in redis? I am using Laravel 5.
From the documentation, the Cache class (Facade):
provides a unified API for various caching systems.
One of which is Redis. Another is Memcache. This class serves as a wrapper to abstract functionality to allow you to be technology agnostic. Ideally so you can swap out the underlying caching system without changing application code.
However, by abstracting you can lose functionality specific to a technology. So the Redis class is specific to Redis. If you require Redis specific functionality, you'd need to use this class directly.

Resources