Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:29:05+00:00 2026-06-09T04:29:05+00:00

This question is specifically pertaining to Couchbase, but I believe it would apply to

  • 0

This question is specifically pertaining to Couchbase, but I believe it would apply to anything with the memcached api.

Lets, say I am creating a client/server chat application, and on my server, I am storing chat session information for each user in a data bucket. Well after the chat session is over, I will remove the session object from the data bucket, but at the same time I also want to persist it to a permanent NoSQL datastore for reporting and analytics purposes. I also want session objects to be persisted upon cache eviction, when sessions timeout, etc.

Is there some sort of “best practice” (or even a function of Couchbase that I am missing) that enables me to do this efficiently and maintaining best possible performance of my in memory caching system?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:29:07+00:00Added an answer on June 9, 2026 at 4:29 am

    Using Couchbase Server 2.0, you could setup two buckets (or two separate clusters if you want to separate physical resources). On the session cluster, you’d store JSON documents (the value in the key/value pair), perhaps like the following:

    { 
      "sessionId" : "some-guid",
      "users" : [ "user1", "user2" ],
      "chatData" : [ "message1", "message2"],
      "isActive" : true,
      "timestamp" : [2012, 8, 6, 11, 57, 00]
    }
    

    You could then write a Map/Reduce view in the session database that gives you a list of all expired items (note the example below with the meta argument requires a recent build of Couchbase Server 2.0 – not the DP4.

    function(doc, meta) {
      if (doc.sessionId && ! doc.isActive) {
        emit(meta.id, null);
      }
    }
    

    Then, using whichever Couchbase client library you prefer, you could have a task to query the view, get the items and move them into the analytics cluster (or bucket). So in C# this would look something like:

    var view = sessionClient.GetView("sessions", "all_inactive");
    foreach(var item in view) 
    {
       var doc = sessionClient.Get(item.ItemId);
       analyticsClient.Store(StoreMode.Add, item.ItemId, doc);
       sessionClient.Remove(item.ItemId);
    }
    

    If you instead, wanted to use an explicit timestamp or expiry, your view could index based on the timestamp:

    function(doc) {
       if (doc.sessionId && ! doc.isActive) {
          emit(timestamp, null);
       }
    }
    

    Your task could then query the view by including a startkey to return all documents that have not been touched in x days.

    var view = sessionClient.GetView("sessions", "all_inactive").StartKey(new int[] { DateTime.Now.Year, DateTime.Now.Months, DateTime.Now.Days-1);
    
    foreach(var item in view)
    {
       var doc = sessionClient.Get(item.ItemId);
       analyticsClient.Store(StoreMode.Add, item.ItemId, doc);
       sessionClient.Remove(item.ItemId);
    }
    

    Checkout http://www.couchbase.com/couchbase-server/next for more info on Couchbase Server 2.0 and if you need any clarification on this approach, just let me know on this thread.

    — John

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question relates specifically to JavaScript, but I imagine would apply to any language.
I have searched for topics specifically to this question but have not found anything
This question is specifically for .net CF, but it should apply to any slow,
This question is specifically about PHP, but I'm guessing it might be applicable to
This question specifically relates to my experience with PHP, but there's no reason why
(I've read a lot about 64-bit versus 32-bit OS/Apps, but this question is specifically
I'm specifically using OS X Terminal.app for command line stuff, but this question may
This question pertains specifically to shell scripts, but could be about any programming language.
Hey all -- this question is specifically about a gender validation, but I'm interested
(This question specifically in C#, but applies generally to .NET) I have a largish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.