We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

mongo problem

Hi all,

I want to cache my createBuilder result with mongo but i couldt get him. I dont know how can i solve it,

$frontCache = new Phalcon\Cache\Frontend\Base64(array(
    "lifetime" => 172800
 ));

 //Create a MongoDB cache
 $cache = new Phalcon\Cache\Backend\Mongo($frontCache, array(
    'server' => "mongodb://localhost",
    'db' => 'popsbuy',
    'collection' => 'products'
 ));

//ana sayfa ürünleri cacheleniyor
$cacheKey = 'products_main_page.cache';
$products    = $cache->get($cacheKey);

if ($products === null) {

            //popüler ürünler çekiliyor
$products = $this->modelsManager->createBuilder() ->columns(array('Product._like','comment_count','title','price_lower','price','image','AffiliateOffers.name','AffiliateOffers.seo_title','payout_yuzde','payout_nakit','payout_type','liked_users','xml_id','brand','model','AffiliateCompanies.tracking_id','Product.url','currency')) 
                    ->from('Product')
                    ->join('AffiliateOffers','Product.aff_id = AffiliateOffers.af_id AND Product.offer_id = AffiliateOffers.af_offer_id')
                    ->join('AffiliateCompanies','AffiliateCompanies.af_id = AffiliateOffers.af_id')
                    ->where('Product.status = 1')
                    ->andWhere('AffiliateOffers.status = 1')
                    ->limit(20)
                    ->orderBy('lastlike_time desc,id desc')
                    ->getQuery()
                    ->execute();

            // Store it in the cache
            $cache->save($cacheKey, $products);
}

really thanks.

Phalcon\Cache\Frontend\Base64 works only with strings, execute() returns an object/array which cannot be encoded with BASE64.

You probably need to use Phalcon\Cache\Frontend\Data instead.

Hello

I hope this example will help i also have the tha same problem with mongo just visit https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/