코우치베이스 모바일

New in Couchbase Mobile v1.3: Document Expiration

Document expiration, sometimes referred to as “time to live” , or TTL, has been a feature of 카우치베이스 서버 for some time.  The new release of version 1.3 adds this capability to 코우치베이스 모바일.  Let’s explore a little.

Documents and Revisions

Couchbase stores data in the form of 제이슨 documents.  More precisely, Couchbase stores revisions of documents.  The details go outside the scope of what I want to focus on here, but revisions are important to understand.  You can read more about them in this guide.

Deleting versus Purging

In your local database, you really only want to store what’s necessary.  Let’s suppose for some reason a particular document is no longer relevant.  Say, for example, a transaction has completed, and the user no longer wants to keep the details around.

You could delete the document.  This has two effects.  First, the document isn’t entirely gone locally.  Couchbase Lite keeps some revision information and replaces the document with a “tombstone” entry.  Second, the fact that the document has been deleted gets propagated to any replications.

So deleting a document doesn’t entirely free up space on your device.  And you may not want to delete the document in other copies of the database.  In our example, you can imagine the user doesn’t want the details of the transaction on their device currently, but may want to retrieve them again later.

Purging a document does something quite different.  Purging a document removes all traces of it, but only in the local database.  If you’re syncing your database, it can help to think of a purged document as one that never got replicated locally to begin with.  The document still exists remotely.  In fact, if the remote version changes, the document could show up in the replication feed, so you can end up with a local copy again.

This fits nicely with our example.  A user  no longer cares about the details of a transaction, so the records get removed locally, freeing up space.  If something changes in the details of the transaction, an app could see those changes passed in a replication, and alert the user.

Expiration = Automated Purging

Now, back to document expiration.  I told you that other information to put expiration in context.  When a document expires, it automatically gets treated like it was purged.

To have a document expire, you set an expiration date on it.  Here’s a code snippet that shows how to do that in Java.

You can see that you’re setting an absolute time, not a relative one.  Once that time has passed, the document behaves as if it has been purged.

I say behaves as if it has been purged.  It can take a little time to process things behind the scenes.  The document will actually be purged, but that can get delayed briefly for various reasons.  Just don’t expect millisecond accuracy.

추신

저희 쪽에서 더 많은 자료를 확인해 보세요 개발자 포털 그리고 트위터에서도 팔로우하세요 @CouchbaseDev.

당사는 다음 곳에 질문을 게시할 수 있습니다. 포럼. 그리고 우리는 적극적으로 참여합니다 스택 오버플로.

저를 개인적으로 팔로우하실 수 있습니다 @HodGreeley

이 기사 공유하기

작가

Hod Greeley는 실리콘 밸리에 거주하는 카우치베이스의 개발자 애드보킷(Developer Advocate)입니다. 그는 소프트웨어 엔지니어 및 엔지니어링 매니저로 20년 이상의 경력을 가지고 있습니다. 그는 전산 물리학 및 화학, 컴퓨터 및 네트워크 보안, 금융, 모바일 등 다양한 소프트웨어 분야에서 일해 왔습니다. 2016년 카우치베이스에 합류하기 전에는 삼성에서 모바일 개발자 관계(developer relations)를 이끌었습니다. Hod는 컬럼비아 대학에서 화학물리학 박사 학위를 받았습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.