Cacheable: a simple gem for caching methods in Ruby

Today we’re releasing a new gem that makes it easy to add caching to any Ruby code. It’s called cacheable!

The cacheable gem is an aspect-oriented, unobtrusive approach to caching. It turns this example code (taken from the Rails caching documentation):

class Product < ApplicationRecord
  def competing_price
    Rails.cache.fetch("#{cache_key}/competing_price") do
      Competitor::API.find_price(id)
    end
  end
end

Into this:

class Product < ApplicationRecord
  cacheable :competing_price

  def competing_price
    Competitor::API.find_price(id)
  end
end

And to help handle more complex caching scenarios, cacheable includes many more powerful features too: conditional caching, dynamic cache key generation, utility methods to skip and clear the cache, and more.

You can read the full story behind cacheable here, and start using cacheable by reading our docs on GitHub. Building cacheable enabled us to clean up Splitwise’s balance-caching code significantly, and it helped us solve several hard-to-diagnose bugs in the process!

Why cacheable?

At Splitwise, we found ourselves writing the same crufty caching code over and over again. Wrapping our code in caching blocks made it harder to read and more difficult to test. And any time that we wanted to perform more complex logic in one of our cached methods – for example, conditional caching – it would cause that method to balloon in size and complexity.

We decided to step back and reexamine our first principles – specifically, the single responsibility principle. We realized that a method like Product#competing_price shouldn’t be responsible for caching at all! We began to think, “What if we could extract the caching logic from our cached methods? What if each method was only responsible for its own logic, and the caching could be tested and built separately?”

Enter aspect-oriented programming (AOP). By switching to an aspect-oriented approach, we were able to build a caching framework that was easier to use, easier to test, and MUCH more reliable across the various parts of our codebase.

Try it yourself!

We’ve been using cacheable in production on Splitwise for many months, and today we’re excited to share it with the rest of the world 🙂 Check out our docs on GitHub for complete instructions on how to start using cacheable in your own Ruby app. We look forward to making additional improvements, and we welcome enhancements and pull requests from the Ruby community!

Upgrades to our PayPal mobile integration

Splitwise is excited to announce that we’ve upgraded our PayPal integrations on iOS and Android to the latest technology from PayPal. We believe the changes made increase the usability, security, and reliability of the integration.

As part of the upgrade process, the PayPal mobile integration was temporarily unavailable on iOS and Android for several weeks starting Friday, June 29th, 2018. (You may have seen an “under construction” message on the PayPal button.) During the upgrade, the PayPal integration on web (splitwise.com) remained live.

Change Log:

Updated 10/17 Belatedly updated to reflect that the update has been completed and the changes are live; Splitwise+PayPal integration is once again usable on all platforms

Updated 8/20 Updated to reflect late August roll out
Updated 7/16 
Updated to reflect expected launch date (early August 2018)

 

Preview/Feedback: Splitwise v2.5 (web)

Splitwise is planning a big redesign of the website and mobile apps for winter 2013, based on all the things we’ve learned since this past August. We’re releasing some intermediate changes to the website over the next few days – please, let us know your feedback!

Continue reading Preview/Feedback: Splitwise v2.5 (web)

Splitwise is temporarily down

UPDATE 2: And we’re back! Site performance may be a little slower than usual while we restore service – please bear with us, and let us know if you have any issues.

UPDATE: An Amazon AWS outage in North Virginia is affecting a number of sites, including Splitwise, Foursquare, GitHub, and others. We will update this post as the situation develops. Read more »

Our hosting provider is currently experiencing some infrastructure issues. They’re working on a resolution and we expect to be back online shortly.

Very sorry for the interruption – thanks for bearing with us!

Debts Made Simple

Ever get caught in a debt triangle? You know: Mike owes you $20 for the electric bill, but he’s waiting for Anna to pay him for back for pizza last weekend, and she’s waiting for you to pay her back for those movie tickets…

In the end, nobody owes anyone anything – but until you figure that out, it’s one giant pain in the neck.

Luckily, you’ve got Splitwise. And we have some cool new features for you. Continue reading Debts Made Simple

When Fairness Backfires

The J.C. Penney logo
J.C. Penney has struggled after introducing new “fairer” prices this spring.

In most money matters, it pays to be fair. (Certainly when paying back your friends.) But when big businesses try to be fair to their customers, sometimes it can backfire in a big way.

Take J.C. Penney. Back in February, they hired a new CEO, Ron Johnson (who built Apple Inc.’s retail operation) to revamp their declining sales. The department store chain then made some radical changes to their pricing.  They eliminated coupons, got rid of confusing fine print, and cut back from over 500 sales a year to just 12. The goal was to make shopping simpler, more transparent, and fairer for consumers.

Five months later, sales are tanking and stock prices have fallen more than 30%. But why? And is it possible for a company to be honest and still turn a profit? Continue reading When Fairness Backfires

Splitwise 1.6.1 for iPhone released

Hey Splitwise users! Version 1.6.1 of our iPhone app, which fixes the serious stability bug introduced in version 1.6, has just been released on the App Store. Download it now!

We at Splitwise would like to apologize again to anyone who experienced crashing issues with v1.6 (and to give a big thanks to those of you who helped us diagnose the problem!). Splitwise is going through big changes on the web and on mobile, and we’ve got some very exciting things to show you – soon 🙂

As always, feel free to ask us any questions via the comments below, or by emailing us at support@splitwise.com. Happy splitting!

– Ryan