예제 #1
0
 public function testRemember()
 {
     $this->assertEquals("bar2", $this->cache->remember("foo2", function () {
         return "bar2";
     }));
     $this->assertEquals("bar2", $this->cache->remember("foo2", function () {
         return "this will never be set";
     }));
 }
예제 #2
0
 /**
  * Loads details about one or more packages.
  *
  * @param string|array $packages
  * @return array
  * @throws NotFoundHttpException if the package doesn't exist
  * @throws LoadingException if the package couldn't be loaded
  */
 public function getPackageDetails($packages)
 {
     $key = 'marketplace.details.' . implode('|', (array) $packages);
     return $this->cache->remember($key, 10, function () use($packages) {
         if (is_string($packages)) {
             return $this->getSinglePackageDetails($packages);
         } else {
             return $this->getMultiplePackageDetails($packages);
         }
     });
 }
예제 #3
0
 public static function read($group)
 {
     return Cache::remember('admin_config_' . $group, function () use($group) {
         $o = new Object();
         return $o->requestAction('/config/get/' . $group);
     }, 'admin_config');
 }
예제 #4
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $extras = Cache::remember('extras_global', 10, function () {
         return Extra::where('approved', '=', '1')->take(25)->orderBy('created_at')->get();
     });
     return View::make('extra.index_extra', array('extras' => $extras));
 }
예제 #5
0
파일: Tip.php 프로젝트: adminrt/phphub
 public static function getRandTip()
 {
     $tips = Cache::remember(self::CACHE_KEY, self::CACHE_MINUTES, function () {
         return Tip::all();
     });
     return $tips->random();
 }
 public function printTest(Request $request)
 {
     $studentsDcid = $request->get('studentsdcid');
     $fileOption = $request->get('fileOption') ?: 'concat';
     $watermarkOption = $request->get('watermarkOption') ?: 'final';
     if ($studentsDcid) {
         $student = Student::where('dcid', $studentsDcid)->firstOrFail();
     } else {
         $student = \Cache::remember('printTestStudent', 1440, function () {
             return Student::orderByRaw('DBMS_RANDOM.RANDOM')->firstOrFail();
         });
     }
     $form = [(object) ['formid' => $request->get('formid'), 'title' => $request->get('title'), 'responseid' => $request->get('responseid')]];
     $cacheKey = 'printtestformdata' . $request->get('formid') . $request->get('responseid');
     $responses = \Cache::remember($cacheKey, 1440, function () use($form) {
         return Iep::getFormData($form);
     });
     $info = $this->dispatch(new PrintPdf($student, $responses, $fileOption, $watermarkOption));
     if (isset($_GET['html'])) {
         return $info;
     }
     if (!empty($info['file'])) {
         return '<h2><a target="_blank" href="' . asset($info['file']) . '">' . $info['file'] . '</a></h2>';
     }
     return $info;
 }
예제 #7
0
 /**
  * Display a listing of people
  *
  * @return Response
  */
 public function index()
 {
     $persons = Cache::remember('people', 1, function () {
         return DB::table('people')->get();
     });
     echo '<pre>';
     print_r($persons);
     echo '</pre>';
     /* Transaction::chunk(20, function($transactions)
     			{
     			    foreach ($transactions as $transaction)
     			    {
     			        //
     			        
     			    }
     			    echo "new lot </br>";
     			});
     
     	         echo '<pre>';
     	         print_r(DB::getQueryLog());
     	         echo '</pre>';
     	         */
     /*$child =  Child::with('institutes')->find(1);
     
     	         echo '<pre>';
     	         print_r($child->toArray());
     	         echo '</pre>';
                  */
 }
예제 #8
0
 public function isStoryteller()
 {
     return Cache::remember('user-storyteller-' . $this->id, 60, function () {
         $p_id = PermissionDefinition::where('name', 'Storyteller')->firstOrFail()->id;
         return $this->permissions()->where('permission_id', $p_id)->count() > 0;
     });
 }
예제 #9
0
파일: DocsApi.php 프로젝트: Snikius/example
 /**
  * Обертка для кэширования запросов
  * @param $cache_key
  * @param \Closure $query
  * @return mixed
  */
 public function cachedQuery($cache_key, \Closure $query)
 {
     $cache_time = \Config::get('docs-api.cache_time');
     return \Cache::remember($cache_key, $cache_time, function () use($query) {
         return $query();
     });
 }
예제 #10
0
 public function createListOfPages()
 {
     $this->data['items'] = $this->getElementsWhereHasModel('pages', 'tags', $this->tagId, app('veer')->siteId, array("take_pages" => $this->number_of_items), true)->select('id', 'url', 'title', 'small_txt', 'views', 'created_at', 'users_id')->orderBy('manual_order', 'desc')->get();
     $this->data['tagName'] = \Cache::remember('tagNameId' . $this->tagId, 2, function () {
         return \Veer\Models\Tag::where('id', '=', $this->tagId)->pluck('name');
     });
 }
예제 #11
0
 function layout_version($layout = 'main')
 {
     $get_hash = function ($layout) {
         $hash = '';
         $files = [public_path('assets/css/app.css'), public_path('assets/js/app.js'), resource_path('views/layouts/main.blade.php'), resource_path('views/partials/header.blade.php'), resource_path('views/partials/footer.blade.php')];
         if ($layout != 'main') {
             $files[] = resource_path('views/layouts/' . str_replace('.', DIRECTORY_SEPARATOR, $layout) . '.blade.php');
         }
         foreach ($files as $file) {
             $hash .= hash_file('md5', $file);
         }
         return hash('md5', $hash);
     };
     if (App::environment('local', 'development', 'staging')) {
         if (!($hash = config('version.layout.' . $layout))) {
             $hash = $get_hash($layout);
             config(compact('hash'));
         }
     } else {
         $hash = Cache::remember('version.layout.' . $layout, config('version.cache_duration', 5), function () use($get_hash, $layout) {
             return $get_hash($layout);
         });
     }
     return $hash;
 }
예제 #12
0
 public function buildRulebook($owner = -1)
 {
     //Build rulebook or retrieve it from the cache.
     $out = Cache::remember('rulebook', 24 * 60, function () {
         $baseRulebook = [];
         $baseRulebook['sects'] = $this->expandSects(RulebookSect::get());
         $baseRulebook['clans'] = $this->expandClans(RulebookClan::get());
         $baseRulebook['rituals'] = $this->sortByGroups(RulebookRitual::whereNull('owner')->get(), "rituals");
         $baseRulebook['backgrounds'] = $this->sortByGroups(RulebookBackground::orderBy('name')->get(), "backgrounds");
         $baseRulebook['disciplines'] = $this->expandDisciplines(RulebookDiscipline::orderBy('name')->get());
         $baseRulebook['natures'] = RulebookNature::get();
         $baseRulebook['abilities'] = $this->sortByGroups(RulebookAbility::where('owner', null)->orderBy('name')->get(), "abilities");
         $baseRulebook["paths"] = $this->expandPaths(RulebookPath::get());
         $baseRulebook["derangements"] = RulebookDerangement::get();
         $baseRulebook['merits'] = $this->sortByGroups(RulebookMerit::orderBy("cost")->get(), "merits");
         $baseRulebook['flaws'] = $this->sortByGroups(RulebookFlaw::orderBy("cost")->get(), "flaws");
         return $baseRulebook;
     });
     if ($owner != -1) {
         $out['custom_abilities'] = RulebookAbility::where('owner', $owner)->get();
         $out['elder_powers'] = RulebookElderPower::where('owner_id', $owner)->get();
         $out['combo_disciplines'] = RulebookComboDiscipline::where('owner_id', $owner)->get();
         $out['custom_rituals'] = RulebookRitual::where('owner', $owner)->get();
     }
     return Response::json($out);
 }
예제 #13
0
 /**
  * Generate the view of the week for given month and given year
  * with events in this period.
  *
  * @param string $year
  * @param string $week 
  * @return view weekView
  *
  *
  */
 public function showWeek($year, $week)
 {
     // Create week start date on monday (day 1)
     $weekStart = date('Y-m-d', strtotime($year . "W" . $week . '1'));
     // Create the number of the next week
     $nextWeek = date("W", strtotime("next Week" . $weekStart));
     $nextYear = date("Y", strtotime("next Week" . $weekStart));
     // Create week end date - we go till tuesday (day 2) because café needs alternative week view (Mi-Di)
     $weekEnd = date('Y-m-d', strtotime($nextYear . "W" . $nextWeek . '2'));
     // Create the number of the previous week
     $previousWeek = date("W", strtotime("previous Week" . $weekStart));
     $previousYear = date("Y", strtotime("previous Week" . $weekStart));
     // Convert number of prev/next week to verbatim format - needed for correct << and >> button links
     $nextWeek = $nextYear . "/KW" . $nextWeek;
     $previousWeek = $previousYear . "/KW" . $previousWeek;
     $date = array('year' => $year, 'week' => $week, 'weekStart' => $weekStart, 'weekEnd' => $weekEnd, 'nextWeek' => $nextWeek, 'previousWeek' => $previousWeek);
     $events = ClubEvent::where('evnt_date_start', '>=', $weekStart)->where('evnt_date_start', '<=', $weekEnd)->with('getPlace', 'getSchedule.getEntries.getJobType', 'getSchedule.getEntries.getPerson.getClub')->orderBy('evnt_date_start')->orderBy('evnt_time_start')->get();
     $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $weekStart)->where('schdl_due_date', '<=', $weekEnd)->with('getEntries.getPerson.getClub', 'getEntries.getJobType')->get();
     // TODO: don't use raw query, rewrite with eloquent.
     $persons = Cache::remember('personsForDropDown', 10, function () {
         $timeSpan = new DateTime("now");
         $timeSpan = $timeSpan->sub(DateInterval::createFromDateString('3 months'));
         return Person::whereRaw("prsn_ldap_id IS NOT NULL \n\t\t\t\t\t\t\t\t\t\t AND (prsn_status IN ('aktiv', 'kandidat') \n\t\t\t\t\t\t\t\t\t\t OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('clb_id')->orderBy('prsn_name')->get();
     });
     $clubs = Club::orderBy('clb_title')->lists('clb_title', 'id');
     // IDs of schedules shown, needed for bulk-update
     $updateIds = array();
     foreach ($events as $event) {
         array_push($updateIds, $event->getSchedule->id);
     }
     return View::make('weekView', compact('events', 'schedules', 'date', 'tasks', 'entries', 'weekStart', 'weekEnd', 'persons', 'clubs'));
 }
예제 #14
0
 /**
  * Show staff page
  * GET
  *
  * @return Response
  */
 public function ShowStaff()
 {
     $staffs = \Cache::remember('staff', 60, function () {
         return \App\Model\Staff::join('accounts', 'accounts.guid', '=', 'cms_staffs.account_id')->orderBy('rank', 'asc')->get();
     });
     return view('misc.staff', compact('staffs'));
 }
예제 #15
0
 /**
  * Show homepage
  * GET
  *
  * @return Response
  */
 public function showHome()
 {
     $blogs = \Cache::remember('blogs', 60, function () {
         return NewsManager::orderBy('date', 'desc')->take(6)->get();
     });
     return view('news.home', compact('blogs'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $vehiculos = Cache::remember('vehiculos', 10 / 60, function () {
         return Vehiculo::simplePaginate(15);
     });
     return response()->json(['siguiente' => $vehiculos->nextPageUrl(), 'anterior' => $vehiculos->previousPageUrl(), 'datos' => $vehiculos->items()], 200);
 }
 public function get_analytics_data()
 {
     $flot_datas_visits = array();
     $analytics = Config::get('cms::settings.analytics.profile_id');
     if (!empty($analytics)) {
         $id = Config::get('cms::settings.analytics.id');
         $account = Config::get('cms::settings.analytics.account');
         $password = Config::get('cms::settings.analytics.password');
         $pid = Config::get('cms::settings.analytics.profile_id');
         //CACHE DATA
         if (CACHE) {
             $show_data = Cache::remember('analytics_' . $pid, function () use($pid, $account, $password) {
                 $ga = new gapi($account, $password);
                 $ga->requestReportData($pid, array('date'), array('visits'), array('date'), null, date("Y-m-d", strtotime("-30 days")), date("Y-m-d"));
                 $results = $ga->getResults();
                 foreach ($results as $result) {
                     $flot_datas_visits[] = '[' . strtotime($result->getDate()) * 1000 . ',' . $result->getVisits() . ']';
                 }
                 return $show_data = '[' . implode(',', $flot_datas_visits) . ']';
             }, 1440);
             //CACHE DISABLED
         } else {
             $ga = new gapi($account, $password);
             $ga->requestReportData($pid, array('date'), array('visits'), array('date'), null, date("Y-m-d", strtotime("-30 days")), date("Y-m-d"));
             $results = $ga->getResults();
             foreach ($results as $result) {
                 $flot_datas_visits[] = '[' . strtotime($result->getDate()) * 1000 . ',' . $result->getVisits() . ']';
             }
             $show_data = '[' . implode(',', $flot_datas_visits) . ']';
         }
         return $show_data;
     }
 }
예제 #18
0
 protected function rememberAttribute($item, $function)
 {
     $cacheItem = get_class($this) . $this->id . $item;
     //TODO make cache duration tweakable
     $value = \Cache::remember($cacheItem, 1, $function);
     return $value;
 }
예제 #19
0
파일: EveSSO.php 프로젝트: OrthoLoess/reset
 /**
  * @param String|null $code
  * @param User|null $user
  * @return mixed
  */
 public function getAccessToken($code = null, $user = null)
 {
     if ($code) {
         // swap code for access token plus refresh token
         $guzzle = new Client();
         $options = ['headers' => ['User-Agent' => 'Reset app by Ortho Loess, hosted at ' . config('app.url'), 'Authorization' => $this->makeBasicAuthHeader()], 'form_params' => ['grant_type' => 'authorization_code', 'code' => $code]];
         $response = $guzzle->post(config('crest.sso-token-uri'), $options);
         $jsonResponse = json_decode($response->getBody(), true);
         //$this->accessToken = $jsonResponse['access_token'];
         $this->refreshToken = $jsonResponse['refresh_token'];
         return $jsonResponse['access_token'];
     } else {
         // use refresh token to get new access token.
         if (!$user) {
             $user = \Auth::user();
         }
         $token = \Cache::remember('accessToken:' . $user->id, 15, function () use($user) {
             $guzzle = new Client();
             $options = ['headers' => ['User-Agent' => 'Reset app by Ortho Loess, hosted at ' . config('app.url'), 'Authorization' => $this->makeBasicAuthHeader()], 'form_params' => ['grant_type' => 'refresh_token', 'refresh_token' => $user->refreshToken]];
             $response = $guzzle->post(config('crest.sso-token-uri'), $options);
             $jsonResponse = json_decode($response->getBody(), true);
             return $jsonResponse['access_token'];
         });
         return $token;
     }
     // cache access token
 }
예제 #20
0
 public function getAccess2()
 {
     $access_token = \Cache::remember('weixin.access2', 100, function () {
         $content = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . env('WX_ID2', '') . '&secret=' . env('WX_SR2', ''));
         return json_decode($content)->access_token;
     });
     return $access_token;
 }
예제 #21
0
 /**
  * Return data cached via $callback call
  * @param string|array $baseKey - use method name; array - will be jsoned and hashed
  * @param int|\DateTime $minutes
  * @param \Closure $dataCallback
  * @param string|array|null $cacheKeySuffix
  * @param bool $recache - true: update cache forcefully
  * @return mixed
  */
 public function cachedData($baseKey, $minutes, \Closure $dataCallback, $cacheKeySuffix = '', $recache = false)
 {
     $cacheKay = $this->generateCacheKey($baseKey, $cacheKeySuffix);
     if ($recache) {
         \Cache::forget($cacheKay);
     }
     return \Cache::remember($cacheKay, $minutes, $dataCallback);
 }
예제 #22
0
 protected function setupStats($view)
 {
     $size = Cache::remember('statTotalSize', 60, function () {
         return DB::table('path_records')->sum('size');
     });
     $formatted = DisplaySize::format($size, 2);
     $view->with('statTotalSize', $formatted);
 }
예제 #23
0
 /**
  * Check if model's table has column
  *
  * @param \Eloquent $model
  * @param string $column
  * @return bool
  */
 public static function hasColumn($model, $column)
 {
     $table = $model->getTable();
     $columns = \Cache::remember('amigridview.columns.' . $table, 60, function () use($table) {
         return \Schema::getColumnListing($table);
     });
     return array_search($column, $columns) !== false;
 }
예제 #24
0
 public function githubApiProxy($username)
 {
     $cache_name = 'github_api_proxy_user_' . $username;
     //Cache 1 day
     return Cache::remember($cache_name, 1440, function () use($username) {
         $result = (new GithubUserDataReader())->getDataFromUserName($username);
         return Response::json($result);
     });
 }
예제 #25
0
 static function cachedIn($ids = array())
 {
     //        $ids = implode(",",$ids);
     $banners = Cache::remember('banners_' . Config::get('cms.currlang.code'), 60, function () use($ids) {
         //            return Banners::whereRaw("id IN ({$ids})")->get();
         return Banners::find($ids);
     });
     return $banners;
 }
예제 #26
0
 public static function allCached()
 {
     $instance = new static();
     $tableName = $instance->getTable();
     $eloquent = \Cache::remember($tableName . '_all', static::$expireCache, function () use($tableName, $instance) {
         return $instance->all();
     });
     return $eloquent;
 }
예제 #27
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $categories = \Cache::remember('categories_mothers', 25, function () {
         return Category::select('id', 'name')->childsOf('mothers')->actives()->get()->toArray();
     });
     if ($request->wantsJson()) {
         return json_encode($categories);
     }
     return redirect('wpanel/categories');
 }
예제 #28
0
 /**
  * 构建一个DBOperator对象
  * @param string $table
  * @param string $key
  * @param string $meta_key default is 'iid'
  * @return DBOperator
  */
 static function table($table, $key = '', $meta_key = 'iid')
 {
     if (empty($key)) {
         $key = isset(self::$TABLE_PKEY[$table]) ? self::$TABLE_PKEY[$table] : 'id';
     }
     $fields = \Cache::remember('db.cache.' . $table . '.fields', 1, function () use($table) {
         return (new DBOperator($table, 'id'))->fields();
     });
     return new DBOperator($table, $key, $meta_key, $fields);
 }
예제 #29
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $shows = Cache::remember('shows', 15, function () {
         return Show::where('approved', '=', '1')->orderBy('air_date', 'desc')->get();
     });
     if (Sentry::check() && Sentry::getUser()->timezone) {
         return View::make('show.index_show_tz', array('shows' => $shows, 'pageTitle' => 'Esports Catch Up'));
     }
     return View::make('show.index_show', array('shows' => $shows, 'pageTitle' => 'Esports Catch Up'));
 }
예제 #30
0
파일: Controller.php 프로젝트: telenok/news
 public function getNotCachedContent()
 {
     $news = \Cache::remember($this->getCacheKey('news'), $this->getCacheTime(), function () {
         $model = app('\\App\\Vendor\\Telenok\\News\\Model\\News');
         return $model->active()->with('newsShowInNewsCategory')->withPermission()->where(function ($query) use($model) {
             $query->where($model->getTable() . '.url_pattern', $this->newsUrlPattern);
             $query->orWhere($model->getTable() . '.id', $this->newsUrlId);
         })->first();
     });
     return view($this->getFrontendView(), ['controller' => $this, 'news' => $news])->render();
 }