Weave 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

Cws Cognix Cache Bundle Laravel Package

creative-web-solution/cws-cognix-cache-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle Add the bundle to your composer.json:

    composer require creative-web-solution/cws-cognix-cache-bundle
    

    Then enable it in config/bundles.php:

    Cws\Bundle\CognixCacheBundle\CwsCognixCacheCacheBundle::class => ['all' => true],
    
  2. Configure the Bundle Create config/packages/cws_cognix_cache.yaml:

    cws_cognix_cache:
        uri: 'https://your-cognix-server.com/api/cache'  # Replace with your Cognix server URI
    
  3. First Use Case: Clear Cognix Cache Inject the CognixCacheService into a controller or service:

    use Cws\Bundle\CognixCacheBundle\Service\CognixCacheService;
    
    class MyController extends Controller
    {
        public function __construct(private CognixCacheService $cognixCache)
        {
        }
    
        public function clearCache()
        {
            $this->cognixCache->clear();
            return response()->json(['status' => 'Cache cleared on Cognix']);
        }
    }
    

Implementation Patterns

Common Workflows

  1. Cache Clearing in Deployment Hooks Trigger cache clearing post-deploy in post-deploy scripts or Laravel Forge/Envoyer hooks:

    php artisan cognix:cache:clear
    

    Or programmatically:

    Artisan::call('cognix:cache:clear');
    
  2. Conditional Cache Clearing Clear cache only for specific environments or routes:

    if (app()->environment('production')) {
        $this->cognixCache->clear();
    }
    
  3. Integration with Laravel Events Listen to CacheCleared events or custom events to sync with Cognix:

    Event::listen(CacheCleared::class, function () {
        app(CognixCacheService::class)->clear();
    });
    
  4. Custom Cache Invalidation Logic Extend the service to invalidate specific cache keys:

    $this->cognixCache->invalidate(['key1', 'key2']);
    

Best Practices

  • Rate Limiting: Avoid rapid cache clears in loops; batch operations if needed.
  • Logging: Log cache operations for debugging:
    cws_cognix_cache:
        uri: '...'
        log_enabled: true  # Enable in config
    
  • Fallbacks: Handle HTTP errors gracefully:
    try {
        $this->cognixCache->clear();
    } catch (CognixCacheException $e) {
        Log::error('Cognix cache clear failed: ' . $e->getMessage());
    }
    

Gotchas and Tips

Pitfalls

  1. Authentication Issues

    • The bundle assumes the uri includes authentication (e.g., API keys). If Cognix requires headers (e.g., Authorization), extend the service:
      $client = new \GuzzleHttp\Client([
          'headers' => ['Authorization' => 'Bearer YOUR_TOKEN']
      ]);
      $this->cognixCache->setClient($client);
      
  2. URI Misconfiguration

    • Ensure the uri ends with /api/cache or the correct endpoint. Test with:
      php artisan cognix:cache:test-connection
      
  3. CORS/Network Restrictions

    • If Cognix is hosted externally, check for CORS policies or firewall rules blocking requests.
  4. Idempotency

    • Repeated calls to clear() may not be idempotent. Add a check in your logic:
      if (!$this->cognixCache->isCacheEmpty()) {
          $this->cognixCache->clear();
      }
      

Debugging Tips

  • Enable Verbose Logging Add to config/packages/cws_cognix_cache.yaml:

    cws_cognix_cache:
        uri: '...'
        debug: true
    

    Logs will appear in storage/logs/laravel.log.

  • Test Locally Use a mock Cognix endpoint (e.g., Mockoon) to simulate responses before deploying.

Extension Points

  1. Custom HTTP Client Override the default Guzzle client:

    $this->cognixCache->setClient(new \GuzzleHttp\Client(['timeout' => 10]));
    
  2. Add Headers Extend the service to include custom headers:

    $this->cognixCache->setHeaders(['X-Custom-Header' => 'value']);
    
  3. Event Dispatching Dispatch events after cache operations:

    Event::dispatch(new CognixCacheCleared());
    
  4. Cache Key Filtering Implement a filter for partial cache invalidation:

    $this->cognixCache->invalidateMatching('/^user_\d+$/');
    
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.
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table