Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cache Laravel Package

becklyn/cache

View on GitHub
Deep Wiki
Context7

Becklyn Cache Bundle

Provides a simple cache, that should be easy to use and high performance. Warning: for highly concurrent usage you should either prepare the cache in advance or use symfony's own cache, as it has proper cache stampede protection.

Usage

Fetch the simple cache factory and get the cache item:

use Becklyn\Cache\Cache\SimpleCacheFactory;

class MyService
{
    private SimpleCacheItemInterface $cache;

    /**
     */
    public function __construct (SimpleCacheFactory $cacheFactory)
    {
        $this->cache = $cacheFactory->getItem(
            "my.cache.key",
            fn () => $this->loadItems()
        );
    }


    /**
     * Returns the cached or fresh items, depending on several conditions. 
     */
    public function getItems () : array
    {
        return $this->cache->get();
    }
    

    /**
     * Loads the items from the database
     */
    public function loadItems () : array
    {
        // ...
    }
}

Caching Based on Symfony Config

You can either pass the cache key and generator to the getItem() method (like in the example above), or you can additionally pass in resources that should be tracked and can be used for cache invalidation.

If you pass resources, this will be a two-level cache:

  1. first level will be the plain symfony/cache, which is really fast but has no proper way of cache invalidation.
  2. second level will be the ConfigCache which will automatically be invalidated if some of the tracked resources change.
$cacheFactory->getItem(
    "my.cache.key",
    fn () => $this->loadItems(),
    // eg. if your cache status depends on routing resources
    $this->router->getRouteCollection()->getResources()
 );
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony