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

Faststorage Bundle Laravel Package

eduardtrayan/faststorage-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require eduardtrayan/faststorage-bundle
    

    Add to config/bundles.php:

    EduardTrayan\FastStorageBundle\EduardtrayanFaststorageBundle::class => ['all' => true],
    
  2. Publish Config

    php artisan vendor:publish --provider="EduardTrayan\FastStorageBundle\EduardtrayanFaststorageBundle" --tag="config"
    

    Edit config/eduardtrayan_faststorage.php to define your storage backends (e.g., memcache/redis).

  3. First Use Case Inject the FastStorageInterface into a service:

    use EduardTrayan\FastStorageBundle\Storage\FastStorageInterface;
    
    class MyService {
        public function __construct(private FastStorageInterface $storage) {}
    
        public function cacheData(string $key, $value, int $ttl = 3600) {
            $this->storage->set($key, $value, $ttl);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Storage Abstraction Use the FastStorageInterface to switch backends without changing business logic:

    $this->storage->get('key');       // Retrieve
    $this->storage->set('key', $data); // Store
    $this->storage->delete('key');     // Delete
    
  2. Contextual Storage Dynamically select storage via config:

    # config/eduardtrayan_faststorage.php
    default_storage: redis
    storage:
        redis: { host: '127.0.0.1', port: 6379 }
        memcache: { host: '127.0.0.1', port: 11211 }
    

    Override in runtime:

    $this->storage->setStorage('memcache'); // Switch to memcache
    
  3. TTL Management Set time-to-live (TTL) for keys:

    $this->storage->set('temp_data', $data, 60); // Expires in 60 seconds
    
  4. Batch Operations Use mget()/mset() for bulk operations:

    $this->storage->mset(['key1' => 'val1', 'key2' => 'val2']);
    $values = $this->storage->mget(['key1', 'key2']);
    

Integration Tips

  • Caching Layer: Use for transient data (e.g., API responses, session storage).
  • Queue Backends: Replace redis/memcache drivers in Laravel queues by binding the FastStorageInterface to Illuminate\Contracts\Queue\Queue.
  • Event Dispatching: Store event payloads temporarily before processing.

Gotchas and Tips

Pitfalls

  1. Connection Failures

    • The bundle lacks built-in retry logic. Wrap calls in try-catch:
      try {
          $this->storage->get('critical_key');
      } catch (\RuntimeException $e) {
          // Fallback to DB or default value
      }
      
  2. Serialization Issues

    • Memcache/Redis store serialized data. Ensure objects implement Serializable or use json_encode():
      $this->storage->set('user', json_encode($user));
      $data = json_decode($this->storage->get('user'), true);
      
  3. Config Overrides

    • Default storage is set in config/eduardtrayan_faststorage.php. Override via service provider:
      $this->app->bind(FastStorageInterface::class, function ($app) {
          return $app['faststorage']->setStorage('redis');
      });
      

Debugging

  • Check Connections: Verify backend servers are running (redis-cli ping, telnet 127.0.0.1 11211).
  • Log Errors: Enable Laravel’s debugbar to inspect storage operations:
    \Barryvdh\Debugbar\Debugbar::info('Storage', ['key' => $this->storage->get('key')]);
    

Extension Points

  1. Custom Storage Drivers Implement Eduardtrayan\FastStorageBundle\Storage\StorageInterface for new backends (e.g., array for testing):

    class ArrayStorage implements StorageInterface {
        private $data = [];
        public function get($key) { /* ... */ }
        public function set($key, $value, $ttl = null) { /* ... */ }
    }
    

    Register via config:

    storage:
        array: ~
    
  2. Middleware for Storage Create middleware to auto-switch storage based on request context (e.g., X-Storage-Engine header):

    $this->storage->setStorage($request->header('x-storage-engine'));
    
  3. Monitoring Extend the bundle to track metrics (e.g., hits/misses):

    $this->storage->extend(function ($storage) {
        $storage->addListener('get', function ($key, $result) {
            \Log::info("Storage GET: {$key} => " . ($result ? 'HIT' : 'MISS'));
        });
    });
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity