Skip to content

Fix inconsistent config namespace and improve Redis cache compatibility for Laravel 13 #134

Description

@hifzi

Description

After upgrading my application to Laravel 13, I encountered an issue when using Laravolt Indonesia cache with Redis.

The cached value contains serialized Eloquent objects, for example:

O:39:"Illuminate\Database\Eloquent\Collection"

Laravel 13 introduced stricter handling for unserializing cached objects through serializable_classes, which requires adding related classes before cached Eloquent objects can be restored.

This can be solved by adding classes such as:

Illuminate\Database\Eloquent\Collection::class,
Laravolt\Indonesia\Models\Province::class,

However, after further investigation, I think storing Eloquent models directly in Redis cache is not the most optimal approach, especially for reference data such as Indonesian regions.

Using plain array data for Redis cache would be:

  • lighter
  • less coupled with PHP class structure
  • safer across Laravel upgrades
  • not dependent on unserializing Eloquent models

Config Namespace Issue

While investigating the cache issue, I found inconsistent config namespaces.

The published config file is:

config/laravolt/indonesia.php

and ServiceProvider uses:

config('laravolt.indonesia.route.enabled')

However, some parts of the package still use:

config('indonesia.cache.store')
config('indonesia.cache.ttl')
config('indonesia.database.connection')

For example, in src/IndonesiaService.php:

$this->cacheStore = $cacheStore ?? config('indonesia.cache.store');

Because of this, configuration values such as:

INDONESIA_CACHE_STORE=array

are not applied correctly.


Possible Improvements

1. Make config namespace consistent

Use:

config('laravolt.indonesia.xxx')

consistently throughout the package.


2. Add optional cache data format configuration

Example:

'cache' => [
    'ttl' => env('INDONESIA_CACHE_TTL', 3600),
    'prefix' => env('INDONESIA_CACHE_PREFIX', 'indonesia_service'),
    'store' => env('INDONESIA_CACHE_STORE', 'redis'),
    'data_format' => env('INDONESIA_CACHE_DATA_FORMAT', 'model'),
],

Options:

  • model (default, keep current behavior)
  • array (store plain array data)

This keeps backward compatibility while allowing Laravel 13 users to use Redis cache without serialized Eloquent model issues.


I would like to discuss the preferred approach before preparing a pull request.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions