Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the package use mongdbs TTL functionality? #4

Open
Evanion opened this issue Mar 4, 2014 · 2 comments
Open

Does the package use mongdbs TTL functionality? #4

Evanion opened this issue Mar 4, 2014 · 2 comments

Comments

@Evanion
Copy link

Evanion commented Mar 4, 2014

Hello
I was just wondering if the package implements the automatic TTL function in MongoDB?

I noticed that the package adds the last_activity field to the documents. What defines the TTL? is it the session lifetime configuration in Laravels session.php?

@jenssegers
Copy link
Owner

I don't really know, it's using Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler

@Evanion
Copy link
Author

Evanion commented Mar 5, 2014

Looking at the code (both in my Laravel package and the repo on gh), it does contain a function to support TTL:

    public function gc($lifetime)
    {
        /* Note: MongoDB 2.2+ supports TTL collections, which may be used in
         * place of this method by indexing the "time_field" field with an
         * "expireAfterSeconds" option. Regardless of whether TTL collections
         * are used, consider indexing this field to make the remove query more
         * efficient.
         *
         * See: http://docs.mongodb.org/manual/tutorial/expire-data/
         */
        $time = new \MongoDate(time() - $lifetime);

        $this->getCollection()->remove(array(
            $this->options['time_field'] => array('$lt' => $time),
        ));

        return true;
    }

https://github.com/symfony/HttpFoundation/blob/master/Session/Storage/Handler/MongoDbSessionHandler.php#L102

But looking at the system.indexes collection of the database, it doesn't seem like the function is used, since, as I understand it, you need to define the 'last_activity' field as a TTL index (I'm really new to mdb, and my expertise is frontend), and a TTL collection can't use a _id index
http://docs.mongodb.org/manual/core/index-ttl/

How difficult would it be to add TTL support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants