Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
actionpack-page_caching 是将页面缓存到文件中,这样有两个缺点:
redis_page 改为将页面缓存至 redis,nginx 安装 redis 插件后即可直接使用。
Add this line to your application's Gemfile:
gem 'redis_page'
And then execute:
$ bundle
增加文件:config/initializers/redis_page.rb
require "redis"
RedisPage.configure do |config|
# 通过访问 http://cache:ewHN84JZLyRurX@example.com:8081/products/1 来刷新缓存
config.sweeper = { port: 8081, username: 'cache', password: 'ewHN84JZLyRurX' }
config.redis = Redis.new(host: "redis", port: 6379, db: 10)
config.ttl = 604800 # 缓存 1 周后(默认)过期
end
Sidekiq.configure_server do |config|
config.redis = { url: "redis://redis:6379/15" }
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://redis:6379/15" }
end
生成页面缓存
class ProductController < ActionController::Base
caches_redis_page :show # 或者使用下面两行的格式
#caches_redis_page :show, append_country: true # cache key 会在 path 后面加上国家代码,例如:/products-US
#caches_redis_page :show, unless: Proc.new { params[:preview] } # 带上 preview 参数,则不进行缓存,方便管理员对未保存的内容进行预览
#caches_redis_page :show, namespace: 'www' # 多个子域名的 path 可能相同,可以使用 namespace 来区分
def show
@product = Product.find(params[:id])
end
end
记录哪些实体更新时要刷新的 url,例如:iPhone 在首页中显示了,则记录下 iPhone 实体与首页的关联关系
- Product.all.each do |product|
= @product.title
修改为:
- c(Product).all.each do |product|
= c(@product).title
c 方法会记录当前页面 url, c(Product) 表示添加、删除商品也会刷新当前页面
更新、删除、添加实体后刷新所有关联的页面缓存
class Product < ActiveRecord::Base
include RedisPage::Sweeper
end
删除子记录时要触发父记录更新
collection.products.delete product
在父记录的 model 关系中增加 after_remove,触发父记录更新
has_many :products, through: :collections_products, after_remove: proc { |a| a.touch }
使用 Sidekiq 执行异步任务,默认的队列名为 redis_page
gem build redis_page.gemspec
gem push redis_page-0.1.1.gem
FAQs
Unknown package
We found that redis_page demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.