Esempio n. 1
0
 /**
  * Returns cached data after updating the cached value if expired
  *
  * @param  string  $key
  * @param  closure $closure
  * @return mixed
  */
 public static function rememberForever($key, $closure)
 {
     if (!isset(static::$cache[$key])) {
         static::$cache[$key] = parent::rememberForever($key, $closure);
     }
     return static::$cache[$key];
 }
 /**
  * Bootstrap the application services.
  */
 public function boot()
 {
     parent::boot();
     $this->publishMigrations();
     $app = $this->app;
     if ($app->bound('form')) {
         $app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () {
                 $records = Country::get(['name', 'cca2']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['cca2']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
         $app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
             $countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
                 $records = Country::get(['name', 'id']);
                 $countries = new Collection();
                 $records->map(function ($item) use(&$countries) {
                     $countries[$item['id']] = $item['name']['official'];
                 });
                 return $countries->sort();
             });
             return $app->form->select($name, $countries, $selected, $options);
         });
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $system = Cache::rememberForever('systemSetting', function () {
         return (object) $this->settingRepository->first()->toArray();
     });
     return view('dashboard.system_setting.index', compact('system'));
 }
Esempio n. 4
0
 public function getAllTagsForContentType($contentType)
 {
     return Cache::rememberForever('tags_all_content_type_' . $contentType, function () use($contentType) {
         $contentTypeId = $this->getContentTypeId($contentType);
         $hashIdsForContentTypeId = $this->getHashIdsForContentTypeId($contentTypeId);
         $distinctTags = $this->getDistinctTagsFromHashIds($hashIdsForContentTypeId);
         return $distinctTags;
     });
 }
 public function get()
 {
     if (!Cache::has('settings')) {
         Cache::rememberForever('settings', function () {
             return $this->setting->first();
         });
     }
     return Cache::get('settings');
 }
 /**
  * @param View $view
  */
 public function compose(View $view)
 {
     if (!Cache::has('this_user')) {
         Cache::rememberForever('this_user', function () {
             return $this->user->thisUser($this->auth->user()->id);
         });
     }
     $view->with('user', Cache::get('this_user'));
 }
 public function provider()
 {
     return function ($app) {
         $parsedRoutes = Cache::rememberForever('haljson.mapping', function () use($app) {
             return $this->parseRoutes(new Mapper($app['config']->get('haljson')));
         });
         return new HalJsonSerializer(new HalJsonTransformer($parsedRoutes));
     };
 }
 public function getRoleId()
 {
     if (!Cache::has('role_id')) {
         Cache::rememberForever('role_id', function () {
             return $this->auth->user() !== null ? $this->user->getRoleId($this->auth->user()->id) : 0;
         });
     }
     Cache::get('role_id');
 }
 /**
  * Register the service provider.
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . self::PATH, 'haljson');
     $this->app->singleton(\NilPortugues\Laravel5\HalJsonSerializer\HalJsonSerializer::class, function ($app) {
         $mapping = $app['config']->get('haljson');
         $key = \md5(\json_encode($mapping));
         return Cache::rememberForever($key, function () use($mapping) {
             return new HalJsonSerializer(new HalJsonTransformer(self::parseRoutes(new Mapper($mapping))));
         });
     });
 }
 /**
  * Register the service provider.
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . self::PATH, 'jsonapi');
     $this->app->singleton(JsonApiSerializer::class, function ($app) {
         $mapping = $app['config']->get('jsonapi');
         $key = md5(json_encode($mapping));
         return Cache::rememberForever($key, function () use($mapping) {
             return new JsonApiSerializer(new JsonApiTransformer(self::parseRoutes(new Mapper($mapping))));
         });
     });
 }
Esempio n. 11
0
 public function selectCountryWithId($app)
 {
     $app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
         $countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
             return Models\Country::get(['name', 'id'])->mapWithKeys(function ($item) {
                 return [$item['id'] => $item['name']['common']];
             })->sort();
         });
         return $app->form->select($name, $countries, $selected, $options);
     });
 }
 public function provider()
 {
     return function ($app) {
         if (config('app.debug')) {
             $parsedRoutes = $this->parseRoutes(new Mapper($app['config']->get('jsonapi')));
         } else {
             $parsedRoutes = Cache::rememberForever('jsonapi.mapping', function () use($app) {
                 return $this->parseRoutes(new Mapper($app['config']->get('jsonapi')));
             });
         }
         return new JsonApiSerializer(new JsonApiTransformer($parsedRoutes));
     };
 }
 private function refreshLanguage()
 {
     $language = App::make(LanguageInterface::class);
     $key = 'default_language';
     Cache::forget($key);
     Cache::rememberForever($key, function () use($language) {
         return $language->whereDefault(1)->firstOrFail();
     });
     $key = 'active_languages';
     Cache::forget($key);
     Cache::rememberForever($key, function () use($language) {
         return $language->whereActive(1)->get();
     });
 }
 /**
  * Retrieve from cache if not empty, otherwise store results
  * of query in cache
  *
  * @param  string   $key
  * @param  Builder  $query
  * @param  string   $verb Optional Builder verb to execute query
  *
  * @return Collection|Model|array|null
  */
 protected function cache($key, Builder $query, $verb = 'get')
 {
     $actualKey = $this->indexKey($key);
     $fetchData = function () use($actualKey, $query, $verb) {
         $this->log('refreshing cache for ' . get_class($this) . ' (' . $actualKey . ')');
         return $this->callQueryVerb($query, $verb);
     };
     if ($this->enableCaching) {
         if ($this->cacheForMinutes > 0) {
             return CacheFacade::remember($actualKey, $this->cacheForMinutes, $fetchData);
         }
         return CacheFacade::rememberForever($actualKey, $fetchData);
     }
     return $fetchData();
 }
 public function __construct()
 {
     $this->client = new \Google_Client();
     $this->client->setClientId($this->ClientId);
     $this->client->setClientSecret($this->ClientSecret);
     $this->client->refreshToken($this->refreshToken);
     $this->service = new \Google_Service_Drive($this->client);
     // we cache the id to avoid having google creating
     // a new folder on each time we call it,
     // because google drive works with 'id' not 'name'
     // & thats why u could have duplicated folders under the same name
     Cache::rememberForever('folder_id', function () {
         return $this->create_folder();
     });
     $this->folder_id = Cache::get('folder_id');
 }
Esempio n. 16
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @param  string|null $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('login');
         }
     }
     if (!Cache::has('role.' . Auth::id())) {
         Cache::rememberForever('role.' . Auth::id(), function () {
             return Auth::user()->role;
         });
     }
     return $next($request);
 }
Esempio n. 17
0
 /**
  * Get setting key to value
  *
  * @param $key
  * @param $default
  *
  * @return null
  */
 public function get($key, $default = null)
 {
     try {
         $settings = Cache::rememberForever($this->cacheKey, function () {
             // Fetch from database
             $settings = Model::get(['key', 'value']);
             // Convert key -> value array
             $arr = [];
             foreach ($settings as $i) {
                 $arr[$i->key] = $i->value;
             }
             return $arr;
         });
         return isset($settings[$key]) ? $settings[$key] : $default;
     } catch (\Exception $e) {
         return null;
     }
 }
Esempio n. 18
0
 public static function getRoles(array $roleIds = [], $types = [], $resources = [])
 {
     if (self::$use_cache) {
         $roles = Cache::rememberForever(self::$cache_key, function () {
             $roles = static::with('users', 'permissions')->get();
             $result = new Collection();
             foreach ($roles as $role) {
                 $result[] = new AclRole($role);
             }
             $cache_prefix = Config::get('acl::cache_key', '_volicon_acl_');
             Cache::forever($cache_prefix . '_last_role_update', new MicrotimeDate());
             return $result;
         });
         /* @var $roles \Illuminate\Support\Collection */
         $need_filter = count($roles) || count($types) || count($resources);
         $roles = !$need_filter ? $roles : $roles->filter(function ($role) use($roleIds, $types, $resources) {
             return !($roleIds && !in_array($role->role_id, $roleIds) || $types && !in_array($role->type, $types) || $resources && !array_intersect($role->permissions->lists('resource'), $resources));
         });
         return $roles;
     }
     $roles = static::with('users');
     $roles->with(['permissions' => function ($query) use($resources) {
         if (!$resources) {
             return;
         }
         $groupResources = GroupResources::getGroupResources();
         $resourcesIds = [];
         foreach ($resources as $resource) {
             $resourcesIds[] = $groupResources->search($resource);
         }
         $query->whereIn('permission_id', $resourcesIds);
     }]);
     if ($types) {
         $roles->whereIn('type', $types);
     }
     if ($roleIds) {
         $roles->whereIn('role_id', $roleIds);
     }
     $result = new Collection();
     foreach ($roles->get() as $role) {
         $result[] = new AclRole($role);
     }
     return $result;
 }
Esempio n. 19
0
 public function index()
 {
     if (!Cache::has('master_page')) {
         Cache::rememberForever('master_page', function () {
             return $this->master_page->getMasterPage();
         });
     }
     $master_page = Cache::get('master_page');
     if ($master_page === null) {
         return view('index::welcome');
     }
     $hidden_fields = $this->render->renderHiddenFields($master_page->hiddenFields);
     if (!Cache::has('master_page_fields')) {
         Cache::rememberForever('master_page_fields', function () use($master_page) {
             return $this->master_page_field->getFieldDetails($master_page->id);
         });
     }
     $master_page_fields = Cache::get('master_page_fields');
     $field_details = $this->render->renderFields($master_page_fields, false);
     return view($master_page->template->folder . '.master_page.index', compact('field_details', 'master_page_fields', 'hidden_fields'));
 }
Esempio n. 20
0
 public function getAllLinks($page, $imagesRoot, $mobile = 0)
 {
     /*Cache::flush();*/
     return Cache::rememberForever('content_all_links_page_' . $page . '_mobile_' . $mobile, function () use($imagesRoot, $mobile) {
         $links = DB::table('links')->leftJoin('users', 'users.id', '=', 'links.creator_id')->leftJoin('content_types', 'links.link_type', '=', 'content_types.id')->where(function ($query) use($mobile) {
             if ($mobile == 1) {
                 $query->where('content_flash', 0);
             }
         })->select('links.id as linkId', 'links.description as linkDescription', 'links.url as linkUrl', 'links.creator_id as creatorId', 'users.name as creatorName', 'links.hash_id as hashId', 'content_types.name as linkType', 'links.image_name as imageName', 'links.image_text as imageText')->orderBy('content_types.name')->paginate(100);
         $linkData = $links->toArray();
         for ($x = 0; $x < sizeof($linkData['data']); $x++) {
             $single = $linkData['data'][$x];
             if (!is_null($linkData['data'][$x]->imageName)) {
                 $linkData['data'][$x]->imageUrl = $imagesRoot . $linkData['data'][$x]->imageName;
             } else {
                 $linkData['data'][$x]->imageUrl = null;
             }
             $data = DB::table('tags_map')->leftJoin('tags', 'tags.id', '=', 'tags_map.tag_id')->where('tags_map.hash_id', $single->hashId)->select('tags.id as tagId', 'tags.name as tagName')->get();
             $linkData['data'][$x]->tags = $data;
         }
         return $linkData;
     });
 }
 public static function addOutputsToChangeAddresses($sendOutPairs, $userId)
 {
     // get change addresses and cache for 12h
     $changeAddresses = ChangeAddress::remember(720, 'change_addresses')->where('user_id', $userId)->get();
     if ($changeAddresses->count() < 1) {
         // no addresses, just return same address:amount pairs
         Log::warning('No change addresses found in DB!');
         return $sendOutPairs;
     }
     $position = Cache::rememberForever(self::NEXT_CHANGE_ADDRESS_POS_KEY, function () {
         return 0;
     });
     $takeNum = self::getOutputsToAdd();
     $addressesToFill = $changeAddresses->slice($position, $takeNum);
     // which addresses to fill with outputs
     // calculate next position where to start slicing on next outputs adding
     $nextPosition = $position + $takeNum;
     // if it took less than 125 addresses, take extra from beginning the remainder
     if ($addressesToFill->count() < $takeNum) {
         // check how much more needs to be taken to have 125 in total
         $remainder = $takeNum - $addressesToFill->count();
         $nextPosition = $remainder;
         // next position for more outputs is the remainder position where to start
         $slicedSecond = $changeAddresses->slice(0, $remainder);
         // take the remainder from beginning
         $addressesToFill = $addressesToFill->merge($slicedSecond);
     }
     Cache::forever(self::NEXT_CHANGE_ADDRESS_POS_KEY, $nextPosition);
     // save the next position
     $amountToAdd = self::getAmountToAdd();
     foreach ($addressesToFill as $address) {
         // add 0.069 btc to pairs
         $sendOutPairs->{$address->address} = $amountToAdd;
     }
     return $sendOutPairs;
 }
Esempio n. 22
0
 public static function findSpecialArticle(SpecialArticle $specialArticle) : Article
 {
     return Cache::rememberForever("article.specialArticle.{$specialArticle}", function () use($specialArticle) {
         return Article::where('technical_name', $specialArticle)->firstOrFail();
     });
 }
Esempio n. 23
0
 /**
  * Retreive a setting by name.
  *
  * @param      $name
  * @param null $for_id
  *
  * @return mixed
  * @throws \Seat\Services\Exceptions\SettingException
  */
 public static function get($name, $for_id = null)
 {
     return Cache::rememberForever(self::get_key_prefix($name), function () use($name, $for_id) {
         // Init a new MODEL
         $value = new static::$model();
         // If we are not in the global scope, add a constraint
         // to be user specific.
         if (static::$scope != 'global') {
             $value = $value->where('user_id', is_null($for_id) ? auth()->user()->id : $for_id);
         }
         // Retreive the value
         $value = $value->where('name', $name)->pluck('value');
         if ($value) {
             return $value;
         }
         // If we have no value, check if we can return
         // a default setting
         if (array_key_exists($name, static::$defaults)) {
             return static::$defaults[$name];
         }
         return null;
     });
 }
Esempio n. 24
0
 /**
  * cachedRoles.
  *
  * @method cachedRoles
  *
  * @return \Illuminte\Database\Eloquent\Collection
  */
 protected function cachedRoles()
 {
     return Cache::rememberForever($this->cacheKey() . 'cacheRoles' . $this->id, function () {
         return $this->roles;
     });
 }
Esempio n. 25
0
 /**
  * Stores the entry in the cache so it is no longer shown
  * in the log results.
  *
  * @return mixed
  */
 public function markRead()
 {
     return Cache::rememberForever($this->makeCacheKey(), function () {
         return $this;
     });
 }
Esempio n. 26
0
 /**
  * Caches an item with the
  * specified key and value forever.
  *
  * @param int|string $key
  * @param \Closure   $closure
  *
  * @return mixed
  */
 public function cacheForever($key, $closure)
 {
     return Cache::rememberForever($key, $closure);
 }
 public function likes_count()
 {
     $this->cacheLikeName = $this->generateName('likes');
     return Cache::rememberForever($this->cacheLikeName, function () {
         $counter = $this->counter();
         return $counter->like_counter ? $counter->like_counter : Config::get('counter.likeStartNumber', 0);
     });
 }
Esempio n. 28
0
 public function rememberForever($key, $callback)
 {
     return Cache::rememberForever($key, $callback);
 }
Esempio n. 29
0
 /**
  * Store the result on cache forever
  *
  * @param array $columns
  * @return mixed
  */
 public function rememberForever(array $columns = ['*'])
 {
     $this->applyCriteria();
     $this->builder->select($columns);
     return Cache::rememberForever($this->generateCacheKey(), function () use($columns) {
         return $this->all($columns);
     });
 }
Esempio n. 30
0
 public function renderFields($page_fields, $isCollect = true, $content_page_id = null)
 {
     if (!Cache::has('_contents')) {
         Cache::rememberForever('_contents', function () {
             return $this->content->allStatus();
         });
     }
     if (!Cache::has('_components')) {
         Cache::rememberForever('_components', function () {
             return $this->component_file->allComponent();
         });
     }
     if (!Cache::has('_blocks')) {
         Cache::rememberForever('_blocks', function () {
             return $this->block->allStatus();
         });
     }
     if (!Cache::has('_pages')) {
         Cache::rememberForever('_pages', function () {
             return $this->page->allStatus();
         });
     }
     if (self::$render === null) {
         if (Cache::get('_contents')->count() > 0) {
             foreach (Cache::get('_contents')->toArray() as $content) {
                 $_contents[$content['id']] = $content;
             }
         }
         if (Cache::get('_components')->count() > 0) {
             foreach (Cache::get('_components')->toArray() as $component) {
                 $_components[$component['id']] = $component;
             }
         }
         if (Cache::get('_blocks')->count() > 0) {
             foreach (Cache::get('_blocks')->toArray() as $k => $block) {
                 $this_block = $_blocks[$block['id']] = $block;
                 foreach ($_blocks[$block['id']]['block_detail'] as $j => $block_detail) {
                     $_blocks[$block['id']]['block_detail'][$block_detail['id']] = $block_detail;
                     unset($_blocks[$block['id']]['block_detail'][$j]);
                 }
             }
         }
         if (Cache::get('_pages')->count() > 0) {
             foreach (Cache::get('_pages')->toArray() as $page) {
                 $_pages[$page['id']] = $page;
             }
         }
         if (isset($_blocks)) {
             foreach ($_blocks as $i => $blok) {
                 foreach ($blok['block_detail'] as $j => $detay) {
                     switch ($detay['type']) {
                         case "block":
                             $_blocks[$i]['block_detail'][$j]['data'] =& $_blocks[$detay['data_id']];
                             break;
                         case "page":
                             $_blocks[$i]['block_detail'][$j]['data'] = $_pages[$detay['data_id']];
                             break;
                         case "content":
                             $_blocks[$i]['block_detail'][$j]['data'] = $_contents[$detay['data_id']];
                             break;
                         case "component-file":
                             $_blocks[$i]['block_detail'][$j]['data'] = $_components[$detay['data_id']];
                             break;
                     }
                 }
             }
             $this->blockTree($_blocks);
         }
         if ($page_fields->count() > 0) {
             foreach ($page_fields as $page_field) {
                 foreach ($page_field['details'] as $i => $field_details) {
                     $field = $_fields[$page_field['field']][] = ['type' => $field_details['type'], 'data_id' => $field_details['data_id'], 'data' => []];
                     switch ($field_details['type']) {
                         case "content":
                             $_fields[$page_field['field']][$i]['data'] = $_contents[$field['data_id']];
                             break;
                         case "component-file":
                             $_fields[$page_field['field']][$i]['data'] = $_components[$field['data_id']];
                             break;
                         case "block":
                             foreach ($_blocks[$field['data_id']]['block_detail'] as $j => $block_detail) {
                                 if ($block_detail['top_block_id'] != null) {
                                     unset($_blocks[$field['data_id']]['block_detail'][$j]);
                                 }
                             }
                             $_fields[$page_field['field']][$i]['data'] = $_blocks[$field['data_id']];
                             break;
                         case "main-content":
                             if ($content_page_id !== null) {
                                 $_fields[$page_field['field']][$i]['data'] = $_pages[$content_page_id];
                             }
                             break;
                     }
                 }
             }
             self::$render = $_fields;
         } else {
             self::$render = [];
         }
     }
     if ($isCollect) {
         return json_decode(json_encode(self::$render));
     } else {
         return self::$render;
     }
 }