Skip to content

Instantly share code, notes, and snippets.

@namusyaka
Last active December 27, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namusyaka/7322812 to your computer and use it in GitHub Desktop.
Save namusyaka/7322812 to your computer and use it in GitHub Desktop.

Upgrade from 0.11.x to 0.12.

Moneta

Need to delete old cache files. (rm -rf ./tmp/*)

and, change the syntax.

# before
Padrino::Cache::Store::File.new(Padrino.root('tmp', app_name, 'cache')

# after
Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache'))

Rack::Protection (from 1.5 to 1.5.1)

Need to rewrite about the protection in config/apps.rb.

# before
set :protection, true

# after
set :protection, :except => :path_traversal

Slim and Haml

Need to use = instead of - in some cases. reference

Mounter

Need to insert app of non-main before main app in config/apps.rb.

url and url_for

Need to fix argument If using incorrect argument.

SampleApp.controllers :cap_alerts do
  get :index do
    "hello"
  end
end

# before
url(:cap_alerts, :index)  #=> "/cap_alerts"
url(:cap, :alerts, :index) #=> "/cap_alerts"
url(:cap, :alerts_index)  #=> "/cap_alerts"

# after
url(:cap_alerts, :index)  #=> "/cap_alerts"
url(:cap, :alerts, :index) #=> UnrecognizedException
url(:cap, :alerts_index)  #=> UnrecognizedException

route.name

# before
route.name #=> :cap_alerts_index

# after
route.name #=> :"cap_alerts index"
@nesquena
Copy link

nesquena commented Jan 1, 2014

Caching Expiration

Change expires_in to expires when declaring this option for the cache

# Basic, page-level caching
class SimpleApp < Padrino::Application
  register Padrino::Cache
  enable :caching

  get '/foo', :cache => true do
    expires 30
    'Hello world'
  end
end

or in a cache block:

# BEFORE
@feed = cache( "feed since #{last_visit}", :expires_in => 60 ) { }
# AFTER
@feed = cache( "feed since #{last_visit}", :expires => 60 ) { }

@nesquena
Copy link

nesquena commented Jan 1, 2014

Additional Caching Chages

Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
Padrino.cache = Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance)
Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice

and then setting keys and getting keys should now be done with:

# BEFORE
MyApp.cache.set('val', 'test')
MyApp.cache.get('val') # => 'test'

# AFTER
MyApp.cache['val'] = 'test'
MyApp.cache['val'] # => 'test'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment