PHPackages                             it-delmax/auth-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. it-delmax/auth-cache

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

it-delmax/auth-cache
====================

Delmax Authentication and Cache Management Package for Laravel

096PHP

Since Feb 18Pushed 2mo agoCompare

[ Source](https://github.com/it-delmax/auth-cache)[ Packagist](https://packagist.org/packages/it-delmax/auth-cache)[ RSS](/packages/it-delmax-auth-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

IT Delmax Auth Cache
====================

[](#it-delmax-auth-cache)

Laravel package for advanced authentication and cache management with Firebird database support.

Features
--------

[](#features)

- 🔥 **High-performance caching** - Redis-based token and user caching
- 🔐 **Firebird integration** - Seamless integration with legacy Firebird databases
- 🚀 **Laravel Sanctum enhancement** - Cached authentication middleware
- ⚡ **Background jobs** - Automatic cache warming and invalidation
- 📊 **Monitoring tools** - Built-in cache statistics and management commands

Installation
------------

[](#installation)

### 1. Add to composer.json

[](#1-add-to-composerjson)

```
{
  "repositories": [
    {
      "type": "path",
      "url": "packages/it-delmax/auth-cache"
    }
  ],
  "require": {
    "it-delmax/auth-cache": "*"
  }
}
```

### 2. Install package

[](#2-install-package)

```
composer install
```

### 3. Regenerate autoload

[](#3-regenerate-autoload)

```
composer dump-autoload
```

### 4. Add to autoload (if needed)

[](#4-add-to-autoload-if-needed)

```
{
  "autoload": {
    "psr-4": {
      "ItDelmax\\AuthCache\\": "packages/it-delmax/auth-cache/src/"
    }
  }
}
```

Configuration
-------------

[](#configuration)

### 1. Update config/auth.php

[](#1-update-configauthphp)

Set the authentication models to use package models:

```
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => ItDelmax\AuthCache\Models\User::class,
    ],
],

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'sanctum',
        'provider' => 'users',
    ],
],
```

### 2. Update config/sanctum.php

[](#2-update-configsanctumphp)

Configure Sanctum to use package PersonalAccessToken model:

```
/*
|--------------------------------------------------------------------------
| Personal Access Token Model
|--------------------------------------------------------------------------
*/
'personal_access_token_model' => ItDelmax\AuthCache\Models\PersonalAccessToken::class,

/*
|--------------------------------------------------------------------------
| Stateful Domains
|--------------------------------------------------------------------------
*/
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
    '%s%s',
    'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
    Sanctum::currentApplicationUrlWithPort()
))),
```

### 3. Database Connections

[](#3-database-connections)

Add Firebird connections to your `config/database.php`:

```
'connections' => [
    'etg_utf8' => [
        'driver' => 'firebird',
        'host' => env('ETG_DB_HOST', 'localhost'),
        'port' => env('ETG_DB_PORT', 3050),
        'database' => env('ETG_DB_DATABASE', 'database'),
        'username' => env('ETG_DB_USERNAME', 'SYSDBA'),
        'password' => env('ETG_DB_PASSWORD', 'masterkey'),
        'charset' => env('ETG_DB_CHARSET', 'UTF8'),
    ],
],
```

### 4. Update config/cache.php

[](#4-update-configcachephp)

Ensure Redis is configured as the cache store:

```
'default' => env('CACHE_STORE', 'redis'),

'stores' => [
    'redis' => [
        'driver' => 'redis',
        'connection' => env('CACHE_REDIS_CONNECTION', 'cache'),
        'lock_connection' => env('CACHE_REDIS_LOCK_CONNECTION', 'default'),
    ],
],
```

### 5. Update config/session.php

[](#5-update-configsessionphp)

Configure sessions to use Redis:

```
'driver' => env('SESSION_DRIVER', 'redis'),
'connection' => env('SESSION_CONNECTION', null),
'store' => env('SESSION_STORE', 'default'),
'domain' => env('SESSION_DOMAIN', '.your-domain.com'),
```

### 6. Update config/queue.php

[](#6-update-configqueuephp)

Configure queue for background jobs:

```
'default' => env('QUEUE_CONNECTION', 'redis'),

'connections' => [
    'redis' => [
        'driver' => 'redis',
        'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
        'block_for' => null,
        'after_commit' => false,
    ],
],
```

### 7. Register Service Provider

[](#7-register-service-provider)

Add to your `config/app.php` providers array (if auto-discovery doesn't work):

```
'providers' => [
    // Other providers...
    ItDelmax\AuthCache\Providers\AuthCacheServiceProvider::class,
],
```

### 8. Environment Variables

[](#8-environment-variables)

```
#Connections
AUTH_CACHE_DB_CONNECTION='etg_utf8'

# Firebird Database
ETG_DB_HOST=your-firebird-server
ETG_DB_PORT=3050
ETG_DB_DATABASE=your-database
ETG_DB_USERNAME=SYSDBA
ETG_DB_PASSWORD=your-password
ETG_DB_CHARSET=UTF8

# Redis Cache
REDIS_HOST=redis
REDIS_PORT=6379
CACHE_STORE=redis
CACHE_PREFIX=your_app_

# Session Configuration
SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_DOMAIN=.your-domain.com

# Queue Configuration
QUEUE_CONNECTION=redis

# Sanctum Configuration
SANCTUM_STATEFUL_DOMAINS=localhost:3000,your-app.test
```

Usage
-----

[](#usage)

### Models

[](#models)

Use the package models in your application:

```
use ItDelmax\AuthCache\Models\User;
use ItDelmax\AuthCache\Models\PersonalAccessToken;

// User model with caching support
$user = User::find(1);

// Cached token verification
$token = PersonalAccessToken::findToken($tokenHash);
```

### Cache Service

[](#cache-service)

```
use ItDelmax\AuthCache\Services\TokenCacheService;

$cacheService = app(TokenCacheService::class);

// Warm user cache
$cacheService->warmUserCache($userId);

// Invalidate user data
$cacheService->invalidateAllUserData($userId);

// Get cache statistics
$stats = $cacheService->getCacheStats();
```

### Middleware

[](#middleware)

Add cached authentication middleware:

```
// In your routes
Route::middleware(['auth:sanctum'])->group(function () {
    // Your protected routes
});

// Or use the cached version directly
use ItDelmax\AuthCache\Middleware\CachedSanctumAuth;

Route::middleware([CachedSanctumAuth::class])->group(function () {
    // Lightning-fast authentication
});
```

### Background Jobs

[](#background-jobs)

The package includes automatic cache management:

```
// Manual job dispatch
use ItDelmax\AuthCache\Jobs\WarmUserCacheJob;
use ItDelmax\AuthCache\Jobs\InvalidateExpiredTokensJob;

WarmUserCacheJob::dispatch($userId);
InvalidateExpiredTokensJob::dispatch();
```

Artisan Commands
----------------

[](#artisan-commands)

### Cache Management

[](#cache-management)

Podesavanja: U `config/cache.php`, u sekciji `'stores'`, dodaj `auth_cache` store koji koristi tvoju redis konekciju auth\_cache

```
'stores' => [

    // ... ostali store-ovi ...

    'auth_cache' => [
        'driver' => 'redis',
        'connection' => 'auth_cache', // ← ovo je ključ!
    ],

],
```

U `config/database.php` podesiti cache store za auth cache: ⚠️ `'database' => 1` ovo je jako vazno, da bi koristili psoebnu redis bazu i ovo treba da bude isto na svim app koje treba da dele auth-cache

```
'redis' => [

    'auth_cache' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 1,
    ],
],
```

Koriscenje iz terminala:

```
# Show cache configuration
php artisan auth-cache:config

# Warm cache for specific user
php artisan auth-cache:warm-user 123

# Invalidate all user data
php artisan auth-cache:invalidate-user 123

# Warm samo korisnike
php artisan auth-cache:warm --users

# Warm samo korisnike sa API pristupom
php artisan auth-cache:warm --api-users

# Warm sve tokene za aktivne usere
php artisan auth-cache:warm --tokens

# Warm sve
php artisan auth-cache:warm --all
```

### Scheduled Jobs

[](#scheduled-jobs)

Add to your `routes/console.php`:

```
use ItDelmax\AuthCache\Jobs\InvalidateExpiredTokensJob;
use ItDelmax\AuthCache\Jobs\WarmAllActiveTokensJob;

// Invalidate expired tokens every hour
Schedule::job(new InvalidateExpiredTokensJob())
    ->hourly()
    ->name('cache:invalidate-expired-tokens')
    ->onOneServer();

// Warm all active tokens every 6 hours
Schedule::job(new WarmAllActiveTokensJob())
    ->everySixHours()
    ->name('cache:warm-all-tokens')
    ->onOneServer();
```

Cache Strategy
--------------

[](#cache-strategy)

### TTL Configuration

[](#ttl-configuration)

- **User Cache**: 6 hours
- **Token Cache**: 12 hours
- **API Access**: 24 hours
- **API Slug**: 24 hours

### Performance Benefits

[](#performance-benefits)

- **Cache Hit**: ~1ms response time
- **Cache Miss**: ~25-50ms (with Firebird fallback)
- **99%+ cache hit ratio** with proper warming

Architecture
------------

[](#architecture)

### Models

[](#models-1)

- `User` - Enhanced Laravel user model with Firebird support
- `PersonalAccessToken` - Cached Sanctum token model
- `DmxApi` - API configuration model
- `DmxApiUser` - User API access permissions

### Services

[](#services)

- `TokenCacheService` - Core caching logic with warming/invalidation

### Jobs

[](#jobs)

- `WarmUserCacheJob` - Cache warming for specific users
- `WarmAllActiveTokensJob` - Bulk token cache warming
- `InvalidateExpiredTokensJob` - Cleanup expired tokens
- `InvalidateUserCacheJob` - User data invalidation

### Middleware

[](#middleware-1)

- `CachedSanctumAuth` - High-performance authentication
- `CheckCachedDmxApiAccess` - API access validation

Setup Checklist
---------------

[](#setup-checklist)

After installation and configuration, verify your setup:

```
# 1. Check if classes are loaded
php artisan tinker
>>> class_exists('ItDelmax\AuthCache\Models\User')
>>> exit

# 2. Test cache connection
php artisan cache:stats

# 3. Test database connection
php artisan tinker
>>> ItDelmax\AuthCache\Models\User::count()
>>> exit

# 4. Test token model
php artisan tinker
>>> ItDelmax\AuthCache\Models\PersonalAccessToken::count()
>>> exit

# 5. Start queue worker (for background jobs)
php artisan queue:work --queue=cache

# 6. Test cache warming
php artisan cache:warm-user 1
```

If all commands work without errors, your setup is complete! 🎉

Requirements
------------

[](#requirements)

- PHP ^8.2
- Laravel ^11.0|^12.0
- Laravel Sanctum ^4.0|^5.0
- Redis (for caching)
- Firebird database connection

Contributing
------------

[](#contributing)

This package is developed by IT Delmax team with AI assistance from Claude (Anthropic).

Authors
-------

[](#authors)

- **Nikola Marcic** - Lead Developer
- **Claude (Anthropic AI)** - AI Assistant
- **Delmax IT Team** - Development Team

License
-------

[](#license)

MIT License

Support
-------

[](#support)

For issues and questions:

- GitHub:
- Email:

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance55

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3828422?v=4)[Nikola Marčić](/maintainers/marcha)[@marcha](https://github.com/marcha)

---

Top Contributors

[![marcha](https://avatars.githubusercontent.com/u/3828422?v=4)](https://github.com/marcha "marcha (59 commits)")

### Embed Badge

![Health badge](/badges/it-delmax-auth-cache/health.svg)

```
[![Health](https://phpackages.com/badges/it-delmax-auth-cache/health.svg)](https://phpackages.com/packages/it-delmax-auth-cache)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
