2012-08-05 40 views
1

我在使用我的機架應用程序生成的Memcaching頁面生成中遇到了一些問題。顯示當nginx獲取memcached機架結果時添加了奇怪的字符串

我存儲通過我的齒條的應用程序在內存緩存與(紅寶石)碼下列位產生的頁面:

require 'dalli' 
memcached = Dalli::Client.new("localhost:11211") 
memcached.set(req.path_info, response[2][0]) 

(其中,反應[2] [0]是所生成的HTML代碼)

在我的nginx服務器配置我有以下幾點:

location @rack { 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header Host $host; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_pass http://127.0.0.1:9292; 
} 
location @memcached { 
    set $memcached_key $request_uri; 
    memcached_pass localhost:11211; 
    default_type text/html; 
    error_page 404 = @rack; 
} 
location/{try_files @memcached;} 

這有點兒工作,但不完全:傳遞給我的瀏覽器中的內容現在開始用:

I"¯[<!DOCTYPE html><html ... 

我的問題是: 什麼是額外的位在前面的HTML代碼,我該如何防止它顯示在瀏覽器的結果?

回答

4

達利使用Marshal.dump序列化設置(這樣你可以緩存任意的Ruby對象)的值,那麼,什麼nginx的獲得不僅是在紅寶石的名帥格式字符串,但數據。你看到的額外字節包含編組頭部(格式的版本等)以及表示後面的字節是字符串的字節。

你可以告訴達利存儲對象的原始值,而不是:

memcached.set(req.path_info, response[2][0], nil, :raw => true)