meema / laravel-cloudfront

轻松快速地将您的应用程序与 AWS CloudFront 集成。

1.0.0 2021-03-21 01:20 UTC

This package is auto-updated.

Last update: 2024-09-20 03:51:17 UTC


README

Latest Version on Packagist GitHub Workflow Status StyleCI Scrutinizer Code Quality Total Downloads Discord License

这是一个 AWS CloudFront 的包装包。请注意,虽然此包在生产环境中使用并且功能齐全,但它目前仅关注缓存失效。

欢迎提交 Pull Request 和建议!🙏🏼

laravel-cloudfront package image

💡 使用方法

use Meema\CloudFront\Facades\CloudFront;
use Meema\CloudFront\Jobs\InvalidateCache;

// run any of the following CloudFront methods:
$client = CloudFront::getClient(); // exposes the AWS CloudFront client

$paths = ['/some-path.jpg', '/another/path.png'];
$result = CloudFront::invalidate($paths, string $distributionId = null);

// invalidates everything, which is the equivalent to a item path of `/*`.
$result = CloudFront::reset();

$message = CloudFront::getInvalidation(string $invalidationId, string $distributionId = null);
$messages = CloudFront::listInvalidations(string $distributionId = null);

// it's recommended to invalidate your cache using a job
dispatch(new InvalidateCache($path.'*')); // you may want to add a '*'-wildcard at the end of your path if you whitelisted any query parameters

请注意,对象失效通常需要 60 到 300 秒才能完成。您可以通过查看 CloudFront 控制台 来检查失效状态。

🐙 安装

您可以通过 composer 安装此包

composer require meema/laravel-cloudfront

该包将自动注册自己。

接下来,使用以下命令发布配置文件

php artisan vendor:publish --provider="Meema\CloudFront\Providers\CloudFrontServiceProvider" --tag="config"

接下来,请将以下键及其值添加到您的 .env 文件中。

AWS_ACCESS_KEY_ID=xxxxxxx
AWS_SECRET_ACCESS_KEY=xxxxxxx
AWS_CLOUDFRONT_DISTRIBUTION_ID=xxxxxxx

以下为发布配置文件的内容

return [
    /**
     * IAM Credentials from AWS.
     */
    'credentials' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
    ],

    'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),

    /**
     * Specify the version of the CloudFront API you would like to use.
     * Please only adjust this value if you know what you are doing.
     */
    'version' => 'latest',

    /**
     * Specify the CloudFront Distribution ID.
     * Example format: EBCYQAQALNSKL
     */
    'distribution_id' => env('AWS_CLOUDFRONT_DISTRIBUTION_ID'),

];

🧪 测试

composer test

📈 变更日志

有关最近更改的更多信息,请参阅我们的 发布页面

💪🏼 贡献

有关详细信息,请参阅 CONTRIBUTING

🏝 社区

如有帮助,讨论最佳实践或任何其他可搜索的对话

Laravel CloudFront 在 GitHub 上

与使用此包的其他人闲聊

加入 Meema Discord 服务器

🚨 安全

请查阅 我们的安全策略 了解如何报告安全漏洞。

🙏🏼 致谢

📄 许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 LICENSE

由 Meema, Inc. 以 ❤️ 制作。