Giter Club home page Giter Club logo

cached_rest_model's Introduction

CachedRestModels

CachedRestModels is a gem that attempts to solve performance issues on calling APIs on a centralized way for all applications.

API endpoints are referenced as Attributes, which can be used to compose cached models for your application.

CachedRestModels is based on composition for each model attributes and handle each set of attribute with a separated cache.

CachedRestModels uses ActiveSupport::Cache and Redis as backend.

Goals

The goal of CachedRestModels is to be used as a centralized cache for API calls for all applications.

By using the same cache server (based on Redis), applications doesn't need to hold shared copies of the same data and can rely on the same data.

This is easier for teams to mantain and we can have a single focus point on how to improve performance.

Installation

Add this line to your application's Gemfile:

gem 'cached_rest_model'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cached_rest_model

Usage

Create your own cached model class and extend it from CachedRestModel::Base

Example

class CachedUser < CachedRestModel::Base
end

Create your own cached model attribute module and put it inside CachedRestModel::Attributes module.

Use the Attributes.get method from CachedRestModel::Attributes passing your web service endpoint

Example:

module CachedRestModel
  module Attributes
    module Profile
      def profile
        Attributes.get("profiles/#{self.send(self.class.key_name)}")
      end
    end
  end
end

Include your attributes modules from the on your model class

Example:

class CachedUser < CachedRestModel::Base
  include CachedRestModel::Attributes::Profile
end

TODO

  • Configure REST hosts based on environment
  • Configure external Redis server
  • Handle HTTP errors
  • Parse HTTP responses into objects instead of returning a string
  • Change cache keys to use URN instead of endpoint addresses
  • Expire caches based on events
  • Define a main Attribute to define the existence of the model entity

Dependencies

ActiveSupport Redis

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/filabreu/cached_rest_model.

For more info email me at mailto:[email protected]

cached_rest_model's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.