Server Settings - Memory Variables
Configure application, session, and client variable settings
Overview
The Memory Variables page in the ColdFusion Administrator allows you to configure how ColdFusion handles persistent data across requests. This includes application, session, and client variables, which are essential for maintaining state in web applications. Proper configuration of these settings is critical for both performance and security.
These settings control memory allocation, timeout behavior, and storage mechanisms for different variable scopes. Understanding the tradeoffs between different options helps you optimize your application for both speed and reliability.
Application Variables
Configure application-level variable settings and timeout behavior.
Enable Application Variables
Default Application Timeout
Maximum Application Timeout
Best Practices for Application Variables
- Use for data that needs to be shared across all users
- Initialize in Application.cfc onApplicationStart()
- Use locking (cflock) when modifying application variables
- Avoid storing large datasets in application scope
- Consider using cachePut() for cached data instead
- Remember that application scope is cleared on server restart
Session Variables
Configure session-level variable settings and cookie security options.
Enable Session Variables
Default Session Timeout
Maximum Session Timeout
Use J2EE Session Variables
- More reliable session tracking
- Better clustering support
- Simpler session cookie management
- Compatible with load balancers
Session Cookie Settings
- Strict: Cookies only sent in first-party context
- Lax: Cookies sent with safe cross-site requests (default)
- None: Cookies sent with all requests (requires Secure flag)
Best Practices for Session Variables
- Always enable J2EE sessions for production applications
- Set HTTPOnly and Secure flags on session cookies
- Use SameSite=Lax or Strict to prevent CSRF attacks
- Regenerate session ID after authentication (session fixation prevention)
- Clear sensitive data from session on logout
- Don't store large objects in session scope
- Implement proper session timeout handling in application
- Monitor session memory usage under load
Client Variables
Client variables are a legacy feature, not recommended for new applications. The Memory Variables page has no client variable settings: applications turn on the Client scope with this.clientManagement = true in Application.cfc, and storage is configured on the separate Server Settings > Client Variables page, summarized below.
Client Storage Options
Cookie Storage
- Storage Location
- Data stored in browser cookies
- Pros
- Simple setup, no database required
- Cons
- 4KB size limit, sent with every request, security concerns
Not Recommended: Cookie storage is inefficient and insecure
Database Storage
- Storage Location
- Dedicated database tables (CDATA, CGLOBAL)
- Pros
- Persistent across browser sessions, no size limits
- Cons
- Database overhead, maintenance required
ColdFusion can create the tables for data sources that use its bundled JDBC drivers. Old records must be purged periodically.
Registry Storage
- Platform
- Windows only (Adobe lists registry storage as not available for UNIX)
- Status
- Legacy feature (not recommended)
Not Recommended: Adobe warns registry storage can critically degrade server performance
Default Client Store
this.clientStoragePurge Data for Clients Not Visiting for (days)
Disable Global Client Variable Updates
Why Client Variables Are Considered Legacy
- Session variables provide better performance for temporary data
- Browser localStorage/sessionStorage better for client-side persistence
- Database or cache services better for long-term user data
- Client variables require maintenance (purging old data)
- Security concerns with cookie-based storage
- Modern alternatives are more flexible and efficient
Memory vs Database Storage
Memory Storage (Application/Session Variables)
- Pros:
- Extremely fast access (no I/O overhead)
- No database connection required
- Simple to implement and use
- No serialization overhead for objects
- Cons:
- Data lost on server restart
- Limited by available RAM
- Not shared across clustered servers (without session replication)
- Memory leaks can cause issues
Database Storage (Client Variables)
- Pros:
- Survives server restarts
- Can store much larger datasets
- Accessible across multiple servers
- Can be backed up with regular database backups
- Cons:
- Slower than memory access
- Database overhead and maintenance
- Serialization required for complex objects
- Can cause database contention under load
When to Use Each
- Use Memory (Application/Session): Most web application data, temporary state, caching
- Use Database: Long-term user preferences, audit trails, data that must survive restarts
- Use Cache Services: Large datasets, distributed caching, microservices architecture
Security Best Practices
Session Security
- Enable J2EE Sessions: More secure than ColdFusion sessions
- HTTPOnly Cookies: Prevents XSS attacks from stealing session cookies
- Secure Flag: Ensures cookies only transmitted over HTTPS
- SameSite Attribute: Protects against CSRF attacks
- Session Regeneration: Regenerate session ID after authentication
- Short Timeouts: Reduce exposure window for stolen sessions
Session Fixation Prevention
- Session fixation occurs when attacker sets victim's session ID
- Solution: Regenerate session ID after login
- ColdFusion 10+: Use the sessionRotate() function (ColdFusion sessions with CFID/CFTOKEN only; it does not rotate JSESSIONID when J2EE sessions are enabled)
- J2EE sessions: sessionRotate() does not apply, so use a JEE-specific session rotation approach to issue a new JSESSIONID after login
- Always regenerate on privilege escalation
Session Hijacking Prevention
- Session hijacking occurs when attacker steals session cookies
- Prevention Strategies:
- Use HTTPS exclusively (Secure flag on cookies)
- Enable HTTPOnly flag to prevent JavaScript access
- Implement session timeout and idle timeout
- Validate user agent and IP address (with caution)
- Monitor for suspicious session activity
- Implement proper logout functionality
Data Security in Variables
- Never store passwords or sensitive credentials in session/application scope
- Encrypt sensitive data before storing in variables
- Use secure tokens instead of actual sensitive data
- Clear sensitive data on logout
- Be aware that memory dumps can expose variable data
Performance Considerations
Memory Management
- Each session consumes memory - monitor with longer timeouts
- Application variables shared across all users (efficient)
- Avoid storing large objects or query results in session
- Use weak references for cached objects when possible
- Monitor heap usage related to session count
Calculating Memory Usage
- Formula: Memory = (Sessions × Average Session Size) + Application Scope
- Example: 1000 sessions × 100KB + 50MB app scope = 150MB
- Guideline: Keep session data under 50-100KB per user
- Monitoring: Use FusionReactor or server monitoring tools
Session Cleanup
- ColdFusion automatically cleans up expired sessions
- When a session expires, ColdFusion runs onSessionEnd() if your Application.cfc defines it; the JVM then reclaims the memory
- Don't rely on onSessionEnd() for critical cleanup
- Implement application-level cleanup for important resources
Clustering Considerations
- J2EE sessions required for session replication
- Session replication increases network traffic
- Sticky sessions reduce replication overhead
- Consider external session storage (the Memory Variables page offers Redis as a Session Storage option) for large clusters
- Test failover behavior thoroughly
Common Issues and Solutions
Sessions Not Persisting
- Increase session timeout if appropriate
- Check browser cookie settings
- Verify cookie domain and path configuration
- Ensure consistent HTTPS usage
- Check for session timeout too short
- Look for domain/path mismatch in cookie settings
Memory Issues with Sessions
- Reduce session timeout
- Remove large objects from session
- Increase JVM heap size
- Use external session storage
- Implement session size monitoring
- Check for memory leaks (sessions not expiring)
Application Scope Not Initializing
- Verify application variables are enabled
- Check onApplicationStart() for errors
- Use
applicationStop()to force reinitialization - Ensure
this.nameis set in Application.cfc
Client Variable Database Bloat
- Reduce purge interval
- Disable global client variable updates
- Manually purge old data periodically
- Consider migrating away from client variables
Monitoring and Maintenance
Key Metrics to Monitor
- Active Sessions: Current number of active user sessions
- Session Creation Rate: New sessions per minute/hour
- Average Session Size: Memory consumed per session
- Session Timeout Rate: How many sessions expire vs logout
- Memory Usage: Heap consumption attributed to sessions
- Peak Concurrent Sessions: Maximum simultaneous sessions
Monitoring Tools
- Performance Monitoring Toolset (PMT): Adobe's monitoring tool for ColdFusion request, node, and data source metrics
- FusionReactor: Advanced monitoring and alerting
- SeeFusion: Real-time session monitoring
- JVM Tools: VisualVM, JConsole for heap analysis
Regular Maintenance Tasks
- Review session timeout settings quarterly
- Monitor memory usage trends
- Purge old client variable data (if using client variables)
- Test session failover in clustered environments
- Review and update security settings (cookie flags, etc.)
- Audit session storage for sensitive data