Download the PHP package momentohq/laravel-example without Composer
On this page you can find all versions of the php package momentohq/laravel-example. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download momentohq/laravel-example
More information about momentohq/laravel-example
Files in momentohq/laravel-example
Package laravel-example
Short Description The Laravel weather app to showcase Momento cache driver.
License Apache-2.0
Informations about the package laravel-example
Momento Laravel Example
In this repo, you will see an example of how to integrate a Momento cache into your Laravel app, instead of a Redis or Memcached. What's the benefits, you ask? You don't have to worry about Redis/Memcached nodes! Intrigued? Keep on reading!
Run the app via Docker
Before building a Docker image, create .env
file in docker
directory with the following env variables:
MOMENTO_API_KEY
=MOMENTO_CACHE_NAME
=WEATHER_API_KEY
this is for weather API. Check out OpenWeather to get an API key.
If you don't have a Momento API key, you can generate one using the Momento Console.
Build a Docker image for the app:
Note: Building the laravel-example
image involves compiling the PHP gRPC extension, which will take several minutes to complete.
If you run into the API limits from GitHub, add a GitHub personal access token to your composer configuration:
And run a Docker container with the image:
Manual PHP Setup
You will need to install the following:
Add the repository and dependency to your project's composer.json
:
Add the Momento configuration to the 'stores' section of config/cache.php
, adjusting the cache_name
and
default_ttl
parameters as needed:
Update the cache driver entry in your .env
file:
CACHE_DRIVER=momento
And add the following environment variables into your .env
file:
WEATHER_API_KEY
this is for weather API. Check out OpenWeather to get an API key.MOMENTO_API_KEY
If you don't have a Momento API key, you can generate one using the Momento Console.
Run composer update
to install the necessary prerequisites.
To run this application:
cURL commands
or
or
Exploring the Momento Cache Integration
Examples of different ways to use Momento's Laravel cache client and cache driver can be found in the WeatherController.php.
For examples of using the Momento client directly, check out our PHP SDK examples!
A simple example usage of Momento's Laravel cache driver is extracted below: