deltaprojects / jruby-memcache-client Goto Github PK
View Code? Open in Web Editor NEWThis project forked from ikai/jruby-memcache-client
A wrapper of the Java Whalin MemCache client for JRuby
License: MIT License
This project forked from ikai/jruby-memcache-client
A wrapper of the Java Whalin MemCache client for JRuby
License: MIT License
This projects provides memcached based stores for JRuby. It is a gem based on Ikai Lan's jruby-memcache-client project hosted at http://github.com/ikai/jruby-memcache-client/tree This project is a JRuby wrapper of the Java MemCache library by Greg Whalin http://www.whalin.com/memcached/ In production, the standard Ruby MemCache client can cause a thread to hang. In the Glassfish application server, by default there are 5 Grizzly connectors that handle incoming requests. A site that uses MemCache heavily can quickly cause all Grizzly connectors to block and take down a site. I'm hoping that this work I am doing here will help others adopt JRuby as a production platform for their Ruby on Rails applications. The Ruby MemCache library was never written with threaded applications in mind. All threads use the same socket, and multithreaded mode basically wraps the IO with a Mutex. The Java library provides several features that are not available in the Ruby MemCache library: - connection pooling - socket timeouts. In forks of the Ruby MemCache library this is achieved either with a Mongrel timeout or use of the Ruby Timeout class, which, at least at the writing of this README, will work unpredictably when being used as a failsafe against hanging IO. As of right now this code only provides a very minimal amount of functionality, but it is enough to use with the Rails cache and cache_fu. Installation ------------ This is a ruby gem that can be installed from gemcutter.org. You will first need to install the gemcutter gem and configure your system to use it: jruby -S gem install gemcutter jruby -S gem tumble You will then be able to install the JRuby Memcache Client gem: jruby -S gem install jruby-memcache-client Replacing Rail's MemCache Client -------------------------------- Rails ships with a bundled copy of the MemCache client. This client will prevent you from using this gem instead. Adding the following code into your environment.rb file: if RUBY_PLATFORM =~ /java/i # Based on instructions from http://www.mikeperham.com/2009/03/03/using-memcache-client-16x-in-rails-23/ # Brain surgery to use our own version of memcache-client without # having to modify activesupport directly. # Unload any previous instance of the class if Object.const_defined? :MemCache Object.instance_eval { remove_const :MemCache } end # Pull in the exact version we want gem 'jruby-memcache-client', '1.6.1' # Ensure that the memcache-client path is at the front of the loadpath $LOAD_PATH.each do |path| if path =~ /jruby-memcache-client/ $LOAD_PATH.delete(path) $LOAD_PATH.unshift(path) end end # If Ruby thinks it's already loaded memcache.rb, force # a reload otherwise just require. if $".find { |file| file =~ /\Amemcache.rb\Z/ } load 'memcache.rb' else require 'memcache' end end This will remove the original MemCache client and load our version of the MemCache class instead. Configuration ------------- The JRuby MemCache client uses the same configuration options as the regular MemCache client. Here is how to build the configuration in your environment.rb file: memcache_options = { :namespace => 'fortaleza:production_live:', } memcached_servers = [ ENV['MEMCACHED_LOCATION'] || '0.0.0.0:11211'] # Constant used by libs CACHE = MemCache.new memcached_servers, memcache_options if RUBY_PLATFORM =~ /java/ Note that this may vary based on your particular configuration method and environment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.