session_cache_limiter / session_cache_expire

session_cache_limiter(?string $value = null): string|false — session_cache_expire(?int $value = null): int|false

Reads/sets the HTTP cache policy for session pages: the limiter decides which Cache-Control/Expires headers session_start sends (nocache/private/private_no_expire/public/off) and expire sets their max-age/Expires value in minutes; re-set each request before session_start.

C C23

C23
#include <stdio.h>
#include <string.h>

/* limiter mode -> cache headers, the mapping session_cache_limiter encodes */
static const char *cache_control(const char *limiter, int expire_minutes) {
    if (strcmp(limiter, "nocache") == 0) return "no-store, no-cache, must-revalidate";
    if (strcmp(limiter, "public") == 0) return "public";      /* max-age would follow expire */
    /* private / private_no_expire */
    (void)expire_minutes;
    return "private";
}

int main(void) {
    const char *limiter = "private";
    int expire = 30; /* minutes */
    printf("limiter: %s\n", limiter);
    printf("expire: %d\n", expire);
    /* header the limiter sends (private, max-age = expire*60) */
    printf("private headers: Cache-Control: private, max-age=%d\n", expire * 60);
    printf("nocache headers: Cache-Control: %s\n", cache_control("nocache", expire));
    return 0;
}
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

C++ C++26

C++26
#include <iostream>
#include <string>
#include <unordered_map>

int main() {
    // limiter mode -> Cache-Control value, the mapping session_cache_limiter encodes
    const std::unordered_map<std::string, std::string> modes = {
        {"nocache", "no-store, no-cache, must-revalidate"},
        {"private", "private"},
        {"private_no_expire", "private"},
        {"public", "public"},
    };
    const std::string limiter = "private";
    const int expire = 30; // minutes
    std::cout << "limiter: " << limiter << "\n";
    std::cout << "expire: " << expire << "\n";
    std::cout << "private headers: Cache-Control: private, max-age=" << expire * 60 << "\n";
    std::cout << "nocache headers: Cache-Control: " << modes.at("nocache") << "\n";
    return 0;
}
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

C# v11.0.100

v11.0.100
// limiter mode -> Cache-Control value; the framework equivalent is
// Response.Headers/Cache-Control or [ResponseCache] attributes in ASP.NET
var modes = new System.Collections.Generic.Dictionary<string, string>
{
    ["nocache"] = "no-store, no-cache, must-revalidate",
    ["private"] = "private",
    ["public"] = "public",
};
string limiter = "private";
int expire = 30; // minutes
Console.WriteLine("limiter: " + limiter);
Console.WriteLine("expire: " + expire);
Console.WriteLine("private headers: Cache-Control: private, max-age=" + expire * 60);
Console.WriteLine("nocache headers: Cache-Control: " + modes["nocache"]);
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

Go v1.27.4

v1.27.4
package main

import "fmt"

// limiter mode -> Cache-Control value; the framework equivalent is
// w.Header().Set("Cache-Control", ...) before any body write
func main() {
	modes := map[string]string{
		"nocache": "no-store, no-cache, must-revalidate",
		"private": "private",
		"public":  "public",
	}
	limiter := "private"
	expire := 30 // minutes
	fmt.Println("limiter:", limiter)
	fmt.Println("expire:", expire)
	fmt.Println("private headers: Cache-Control: private, max-age=" + fmt.Sprint(expire*60))
	fmt.Println("nocache headers: Cache-Control: " + modes["nocache"])
}
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

Java v27.0.1

v27.0.1
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        // limiter mode -> Cache-Control value; the framework equivalent is
        // response.setHeader("Cache-Control", ...) in Servlet filters
        Map<String, String> modes = Map.of(
            "nocache", "no-store, no-cache, must-revalidate",
            "private", "private",
            "public", "public");
        String limiter = "private";
        int expire = 30; // minutes
        System.out.println("limiter: " + limiter);
        System.out.println("expire: " + expire);
        System.out.println("private headers: Cache-Control: private, max-age=" + (expire * 60));
        System.out.println("nocache headers: Cache-Control: " + modes.get("nocache"));
    }
}
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

JavaScript v26.13.1

v26.13.1
// limiter mode -> Cache-Control value; the framework equivalent is
// res.set("Cache-Control", ...) in express (before the body)
const modes = {
  nocache: "no-store, no-cache, must-revalidate",
  private: "private",
  public: "public",
};
const limiter = "private";
const expire = 30; // minutes
console.log("limiter:", limiter);
console.log("expire:", expire);
console.log("private headers: Cache-Control: private, max-age=" + expire * 60);
console.log("nocache headers: Cache-Control: " + modes.nocache);
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

PHP v8.6.0

v8.6.0
// session_cache_limiter: picks which Cache-Control headers the session extension sends on
// session_start(). Modes: nocache / private / private_no_expire / public / '' (off).
// Like the cookie params, the setting resets each request and must run BEFORE session_start().
$prev = session_cache_limiter("private");
session_cache_expire(30);                 // minutes; only affects headers when limiter != nocache
$lim = session_cache_limiter();
$exp = session_cache_expire();
$off = session_cache_limiter("");         // '' disables automatic cache headers entirely
$offOk = session_cache_limiter() === "";
$known = in_array($prev, ["", "nocache", "private", "private_no_expire", "public"], true);
echo "prev limiter known: ", var_export($known, true), "\n";
echo "limiter: ", $lim, "\n";
echo "expire: ", $exp, "\n";
echo "off ok: ", var_export($offOk, true), "\n";
echo "nocache headers: Cache-Control: no-store, no-cache, must-revalidate\n";
echo "private headers: Cache-Control: private, max-age=1800";
Output
prev limiter known: true
limiter: private
expire: 30
off ok: true
nocache headers: Cache-Control: no-store, no-cache, must-revalidate
private headers: Cache-Control: private, max-age=1800

Python v3.15.2

v3.15.2
# limiter mode -> Cache-Control value; the framework equivalent is
# an after_request hook (Flask) setting response.headers["Cache-Control"]
modes = {
    "nocache": "no-store, no-cache, must-revalidate",
    "private": "private",
    "public": "public",
}
limiter = "private"
expire = 30  # minutes
print("limiter:", limiter)
print("expire:", expire)
print("private headers: Cache-Control: private, max-age=" + str(expire * 60))
print("nocache headers: Cache-Control: " + modes["nocache"])
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

Rust v1.99.1

v1.99.1
fn main() {
    // limiter mode -> Cache-Control value; the framework equivalent is
    // inserting the header via axum's HeaderValue before the body
    let modes = [
        ("nocache", "no-store, no-cache, must-revalidate"),
        ("private", "private"),
        ("public", "public"),
    ];
    let limiter = "private";
    let expire = 30; // minutes
    println!("limiter: {}", limiter);
    println!("expire: {}", expire);
    println!("private headers: Cache-Control: private, max-age={}", expire * 60);
    let nocache = modes.iter().find(|(k, _)| *k == "nocache").unwrap().1;
    println!("nocache headers: Cache-Control: {}", nocache);
}
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

TypeScript v26.13.1

v26.13.1
// limiter mode -> Cache-Control value; the framework equivalent is
// res.set("Cache-Control", ...) in express (before the body)
const modes: Record<string, string> = {
  nocache: "no-store, no-cache, must-revalidate",
  private: "private",
  public: "public",
};
const limiter: string = "private";
const expire: number = 30; // minutes
console.log("limiter:", limiter);
console.log("expire:", expire);
console.log("private headers: Cache-Control: private, max-age=" + expire * 60);
console.log("nocache headers: Cache-Control: " + modes.nocache);
Output
limiter: private
expire: 30
private headers: Cache-Control: private, max-age=1800
nocache headers: Cache-Control: no-store, no-cache, must-revalidate

Language differences

C: hand-write these headers at the CGI layer (printf into the header block, blank line before the body); cache policy is the application's own job.

C++: same as C; framework layers set the header mapping where responses are assembled.

C#: the framework layer is ASP.NET's Response.Headers.CacheControl or [ResponseCache] / HttpCachePolicy on controllers; hand-write the strings at the language level.

Go: the standard library's w.Header().Set("Cache-Control", ...) plus w.Header().Set("Expires", ...) — PHP's limiter modes are fixed combinations of these headers; set them before any body write.

Java: a Servlet filter's response.setHeader("Cache-Control", ...)/setExpires; Spring Security config classes wrap the same header set.

JavaScript: express's res.set("Cache-Control", ...) or helmet middleware's noCache option; middleware is the framework counterpart of the PHP limiter concept.

PHP: five modes decide the headers session_start() sends automatically — nocache (default) sends no-store, no-cache, must-revalidate plus Pragma and a past Expires; private sends the fixed 1981 Expires plus private, max-age=expire*60; private_no_expire is the private variant with no Expires header (dodging old-browser confusion); public sends a future Expires plus public, max-age; setting the limiter to '' turns the automatic headers off entirely. expire is in minutes (default 180) and only matters when the limiter is not nocache; both settings reset per request and must run before session_start().

Python: at the framework layer set response.headers["Cache-Control"] in Flask's after_request or a Django middleware; nothing built-in matches the limiter.

Rust: axum builds them via the headers::CacheControl builder or inserts them uniformly at a middleware layer; nothing built-in matches the limiter.

TypeScript: same as JavaScript.