问题描述
我按照Heroku的教程使用Memcache。我的目标是缓存我的资产(js / css /图像):https://devcenter.heroku.com/articles/rack-cache-memcached-rails31
我按照说明进行了配置: config / application.rb
import requests
import gspread
import urllib.parse
import pickle
spreadsheetId = "###" # Please set the Spreadsheet ID.
cellRange = "Yoursheetname!A1:A100" # Please set the range with A1Notation. In this case,the hyperlink of the cell "A1" of "Sheet1" is retrieved.
with open('token_sheets_v4.pickle','rb') as token:
# get this file here
# https://developers.google.com/identity/sign-in/web/sign-in
credentials = pickle.load(token)
client = gspread.authorize(credentials)
# 1. Retrieve the access token.
access_token = client.auth.token
# 2. Request to the method of spreadsheets.get in Sheets API using `requests` module.
fields = "sheets(data(rowData(values(hyperlink))))"
url = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "?ranges=" + urllib.parse.quote(cellRange) + "&fields=" + urllib.parse.quote(fields)
res = requests.get(url,headers={"Authorization": "Bearer " + access_token})
print(res)
# 3. Retrieve the hyperlink.
obj = res.json()
print(obj)
link = obj["sheets"][0]['data'][0]['rowData'][0]['values'][0]['hyperlink']
print(link)
config / production.rb
config.cache_store = :mem_cache_store
我也有一个疑问,因为我在运行“ Rake中间件”时没有看到Rack缓存(我有这个
# Code is not reloaded between requests.
config.cache_classes = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Compress JavaScripts and CSS.
config.assets.compress = true
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Use a different cache store in production.
config.cache_store = :mem_cache_store
# Cache static assets
config.serve_static_assets = true
# Generate digests for assets URLs
config.assets.digest = true
client = Dalli::Client.new((ENV["MEMCACHIER_SERVERS"] || "").split(","),:username => ENV["MEMCACHIER_USERNAME"],:password => ENV["MEMCACHIER_PASSWORD"],:failover => true,:socket_timeout => 1.5,:socket_failure_delay => 0.2,:value_max_bytes => 10485760)
config.action_dispatch.rack_cache = {
:metastore => client,:entitystore => client
}
config.public_file_server.headers = { 'Cache-Control' => 'public,max-age=2592000' }
config.action_mailer.perform_caching = false
我也在生产中检查了日志,似乎memcacher正在运行,他只是显示“ miss”而不是存储或新鲜。 我遵循heroku给出的“调试部分”,然后尝试使用:p来检查y资产之一。
use Rack::Sendfile
use Actiondispatch::Static
use Actiondispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::Methodoverride
use Actiondispatch::RequestId
use Sprockets::Rails::QuietAssets
use Rails::Rack::Logger
use Actiondispatch::ShowExceptions
use MetaRequest::Middlewares::Headers
use Actiondispatch::DebugExceptions
use BetterErrors::Middleware
use Actiondispatch::RemoteIp
use Actiondispatch::Reloader
use Actiondispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use Actiondispatch::Cookies
use Actiondispatch::Session::CookieStore
use Actiondispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Warden::Manager
use Rack::Attack
use Rack::Deflater
use ScoutApm::Middleware
use ScoutApm::Instant::Middleware
use MetaRequest::Middlewares::MetaRequestHandler
use MetaRequest::Middlewares::AppRequestHandler
use OmniAuth::Strategies::LinkedIn
run [MY NAME APP]::Application.routes
没有:
X-Rack-Cache:新鲜
似乎在od Rack :: cache的配置中有问题...
您能从哪里找到问题的一个主意吗? 感谢帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)