Scope Storage

Use Couchbase as the storage backend for BoxLang session and application scopes, providing distributed, fault-tolerant scope storage that scales across multiple servers.

Use Couchbase as the storage backend for your BoxLang session and application scopes. This provides distributed, fault-tolerant scope storage that survives application restarts and scales across multiple servers.

🎯 Session Storage

Configuration

Configure Couchbase as your session storage provider in Application.bx:

component {
    this.name = "MyApp";
    this.sessionManagement = true;
    this.sessionStorage = "couchbase-sessions";
    this.sessionTimeout = createTimeSpan(0, 2, 0, 0); // 2 hours

    this.caches["couchbase-sessions"] = {
        "provider": "Couchbase",
        "properties": {
            "connectionString": "couchbase://localhost",
            "username": "Administrator",
            "password": "password",
            "bucket": "myapp",
            "scope": "sessions",
            "collection": "user_sessions"
        }
    };
}

Using Session Scope

Once configured, use the session scope normally:

Benefits

  • Distributed: Sessions survive server restarts

  • Scalable: Share sessions across multiple servers

  • Fast: Sub-millisecond access times

  • Secure: Sessions stored in dedicated collection

🌐 Application Scope Storage

Configuration

Using Application Scope

🔧 Advanced Configuration

Separate Collections for Different Scope Types

Session Clustering

For load-balanced applications:

📊 Monitoring Session Activity

Query Active Sessions

Find Sessions by User

🧹 Session Cleanup

Manual Cleanup

Automatic Expiration

Configure TTL (Time To Live) at the cache level:

🔐 Security Best Practices

1. Use Dedicated Credentials

2. Use TLS/SSL

3. Separate Sensitive Data

🎯 Performance Optimization

Session Granularity

Lazy Loading

🐛 Troubleshooting

Sessions Not Persisting

Check that sessionStorage matches your cache name:

Connection Errors

Verify Couchbase is running and accessible:

Performance Issues

Monitor cache statistics:

🔗 Next Steps

Last updated

Was this helpful?