我正在尝试使用Rails 4中的send_data方法渲染图像时将Cache-Control标头设置为public,但无论我做什么,Rails都会将其更改为私有..
控制器代码:
response.headers['Cache-Control'] = 'public, max-age=31556926'
send_data data, disposition: 'inline'
在浏览器中查看时:
Cache-Control:max-age=31556926, private
如何摆脱这个私人关键字?
答案 0 :(得分:2)
我通过使用expires_in方法解决了这个问题,而不是手动编辑标题:
IF OBJECT_ID('dbo.departmentStats', 'U') IS NOT NULL
DROP TABLE dbo.departmentStats;
CREATE TABLE departmentStats
([Facility] varchar(50), [Department] varchar(50),[Stat] varchar(5),
[January] int, [February] int, [March] int);
INSERT INTO departmentStats
([Facility],[Department],[Stat], [January], [February], [March])
VALUES
('f1','d1','Stat1', 90, 40, 60),
('f1','d1','Stat2', 30, 20, 10);
select 'Original Data' as src,* from departmentStats
IF OBJECT_ID('tempdb.dbo.#pivotstats', 'U') IS NOT NULL
DROP TABLE #pivotstats;
CREATE TABLE #pivotstats
(facility varchar(50),department varchar(50),stat VARCHAR(50),period
varchar(50),value int)
insert into #pivotstats
select facility,department,Stat, period, value
from departmentStats
unpivot
(
value
for Period in (January, February, March)
) u
select 'Original after unpivot' as src,* from #pivotstats
IF OBJECT_ID('dbo.departmentStats2', 'U') IS NOT NULL
DROP TABLE dbo.departmentStats2;
CREATE TABLE departmentStats2
([Facility] varchar(50), [Department] varchar(50),[Period] varchar(20),
[stat1] int, [stat2] int, [Sum] numeric(10,2),[Division] numeric(10,2));
insert into departmentStats2
select
facility
,department
,period
,Stat1
,stat2
,Stat1+Stat2 as [sum]
,case when Stat2<>0 then cast(Stat1/Stat2 AS numeric) else 0.0 end as
division
from #pivotstats
Pivot(
sum(value)
for Stat in ([Stat1],[Stat2])
)
as x
select 'Added formula columns' as src,* from departmentStats2
select 'Union and repivot' as src,* from (
select
facility
,department
,Period
,'Stat1' as Stat
,stat1 as value
from departmentStats2
union all
select
facility
,department
,Period
,'Stat2' as Stat
,stat2 as value
from departmentStats2
union all
select
facility
,department
,Period
,'sum' as Stat
,[SUM] as value
from departmentStats2
union all
select
facility
,department
,Period
,'Division' as Stat
,[Division] as value
from departmentStats2
) as bunion
pivot(
sum(value)
for Period in (January, February, March)
)as P
答案 1 :(得分:0)
我遇到了同样的问题。单独使用expires_in并没有解决它。我最终手动和通过expires_in设置Cache-Control和Expires标头来解决问题。怪异
response.headers["Expires"] = 1.year.from_now.httpdate
response.headers["Cache-Control"] = 'public'
expires_in 1.year, public: true
send_file file