forked from rtomayko/rack-cache
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google AppEngine memcache entity store and metastore implementations
To use GAE's memcache with rack-cache, set the :metastore and :entitystore options as follows: use Rack::Cache, :metastore => 'gae://cache-meta', :entitystore => 'gae://cache-body' The 'cache-meta' and 'cache-body' parts are memcache namespace prefixes and should be set to different values.
- Loading branch information
Showing
7 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'base64' | ||
|
||
module Rack::Cache::AppEngine | ||
|
||
module MC | ||
require 'java' | ||
|
||
import com.google.appengine.api.memcache.Expiration; | ||
import com.google.appengine.api.memcache.MemcacheService; | ||
import com.google.appengine.api.memcache.MemcacheServiceFactory; | ||
import com.google.appengine.api.memcache.Stats; | ||
|
||
Service = MemcacheServiceFactory.getMemcacheService | ||
end unless defined?(Rack::Cache::AppEngine::MC) | ||
|
||
class MemCache | ||
|
||
def initialize(options = {}) | ||
@cache = MC::Service | ||
@cache.namespace = options[:namespace] if options[:namespace] | ||
end | ||
|
||
def contains?(key) | ||
MC::Service.contains(key) | ||
end | ||
|
||
def get(key) | ||
value = MC::Service.get(key) | ||
Marshal.load(Base64.decode64(value)) if value | ||
end | ||
|
||
def put(key, value, ttl = nil) | ||
expiration = ttl ? MC::Expiration.byDeltaSeconds(ttl) : nil | ||
value = Base64.encode64(Marshal.dump(value)).gsub(/\n/, '') | ||
MC::Service.put(key, value, expiration) | ||
end | ||
|
||
def namespace | ||
MC::Service.getNamespace | ||
end | ||
|
||
def namespace=(value) | ||
MC::Service.setNamespace(value.to_s) | ||
end | ||
|
||
def delete(key) | ||
MC::Service.delete(key) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters