承接 momentohq/laravel-example 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

momentohq/laravel-example

Composer 安装命令:

composer create-project momentohq/laravel-example

包简介

The Laravel weather app to showcase Momento cache driver.

README 文档

README

logo

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=<YOUR_API_KEY>
  • MOMENTO_CACHE_NAME=<YOUR_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:

cd docker
docker build --tag laravel-example .

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:

export COMPOSER_AUTH=<YOUR_GITHUB_ACCESS_TOKEN>
docker build --tag laravel-example --build-arg COMPOSER_AUTH=$COMPOSER_AUTH .

And run a Docker container with the image:

docker run -d --env-file .env -p 8000:8000 laravel-example

Manual PHP Setup

You will need to install the following:

Add the repository and dependency to your project's composer.json:

{
  "require": {
    "momentohq/laravel-example": "0.2.3"
  }
}

Add the Momento configuration to the 'stores' section of config/cache.php, adjusting the cache_name and default_ttl parameters as needed:

'stores' => [
        ...
        'momento' => [
            'driver' => 'momento',
            'cache_name' => 'my-momento-cache',
            'default_ttl' => 60,
        ],
],

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:

php artisan serve

cURL commands

curl http://127.0.0.1:8000/api/weather/<your-favorite-city>

Example:
curl http://127.0.0.1:8000/api/weather/denver

or

curl http://127.0.0.1:8000/api/weather/<your-favorite-zipcode>/<country-code-such-as-us>

Example:
curl http://127.0.0.1:8000/api/weather/98101/us

or

curl http://127.0.0.1:8000/api/weather/id/<your-favorite-city-id>

City id can be found here: http://bulk.openweathermap.org/sample/

Example:
curl http://127.0.0.1:8000/api/weather/id/833

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:

$apiKey = env("WEATHER_API_KEY");
$url = "https://api.openweathermap.org/data/2.5/weather?q={$city}&appid={$apiKey}";
$result = Cache::get($city);
if (!is_null($result)) {
    return $result;
} else {
    $res = $this->httpClient->get($url);
    if ($res->getStatusCode() == 200) {
        $json = $res->getBody();
        // 10 minutes TTLc
        Cache::put($city, $json, 600);
        return $json;
    }
}

momentohq/laravel-example 适用场景与选型建议

momentohq/laravel-example 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cache」 「laravel」 「serverless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 momentohq/laravel-example 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 momentohq/laravel-example 我们能提供哪些服务?
定制开发 / 二次开发

基于 momentohq/laravel-example 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 66
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-03-28