What is $cacheFactory? - javascript

I can find absolutely no information on what exactly $cacheFactory is and how it can be useful in your application.
The Angular Documentation says
"Factory that constructs cache objects and gives access to them." -- $cacheFactory
Well, that wasn't at all helpful, what does that mean? There doesn't seem to be anything on Google either.
Can someone please explain What it is & When can it be useful.
Thanks in advance.

Oh the $cacheFactory is simple as i understand it :
If you have a request to retrieve constant data for example like a list of cities.
It's not a good pattern to get this list from the server each time the user go on a form where he has to select a city !
So you have to cache this list. The cacheFactory is done for that !
If you're using $http instead of $resource you can enbale the cache just like that :
$http.get('myUrl', { cache: true })

Related

Display text value from Github Gist in Hugo site

I know I might be asking something quite simple but for the life of me I can't seem to get my head around this and I'm definitely overseeing something simple but I don't know what. Any help would be very appreciated.
I'm generating a static site using Hugo. On one of my pages, I want to create something like a progress bar, using a variable which I need to get from a file from a Github Gist.
Say this is the gist: https://gist.github.com/bogdanbacila/c5a9683089c74d613ad17cdedc08f56b#file-thesis-words-txt
The file only has one number, that's it. What I'm asking is how to get that number from the gist and store it in hugo or at least just display it in some raw html. I want to mention that I'm not looking to use the provided embedded text, I'd rather just get the raw value. At the end of the day all I need is to read and display the number from the raw link here: https://gist.githubusercontent.com/bogdanbacila/c5a9683089c74d613ad17cdedc08f56b/raw/8380782afede80d234209293d4c5033a890e44b6/thesis-words.txt
I've asked this question on the Hugo forum and that wasn't very helpful, instead of providing me with some guidance I got sent here. Here was my original question: https://discourse.gohugo.io/t/get-raw-content-from-github-gist-to-a-variable/38781
Any help would be greatly appreciated, I know there's something very obvious which I'm not seeing, please guide me to the right direction, this doesn't feel like it should be that complicated.
Best,
Bogdan
You could fetch this data and store it in Hugo as a data file but I don't recommend it.
Since Hugo is a static site generator, you would need to not only modify the data files in your repo every time the value changes, but re-build your site as well. Then you have to worry about running the script on a schedule. Meaning you can't be sure that the value is current the second someone visits your site. This is more headache than it's worth in my opinion.
The better route would be to write some client-side JavaScript that makes a call to the raw URL of the gist to get the content. This is Hugo-agnostic which is why I suspect you were pointed here.
From the Gists API docs:
If you need the full contents of the file, you can make a GET request to the URL specified by raw_url.
You can use something like the Fetch API for this or any other JS client. Simply make a GET request to the URL, parse the value from the response body, and write some JavaScript to insert the value in the DOM when someone makes a request to the page it's on.
#wjh18
Cheers! I didn't know about GET requests so I had to dig around for that a little bit but I managed to get it going with this:
<script>
fetch('https://gist.githubusercontent.com/bogdanbacila/c5a9683089c74d613ad17cdedc08f56b/raw').then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
}).catch(function() {
console.log("Booo");
});
</script>

PouchDB data view by-sequence

Is it possible to show PouchDB data order by "by-sequence" (sequence when they insert into PouchDB). I don't want it to order by _id. Please help!
That's easy: use the _changes feed. Just make sure to use the include_docs option to get the complete docs. You can even get new changes continuously to react on live changes.
If you need to sort your views by seq, I think there is an obscure option in CouchDB that enables access to the seq for each document, but it's probably unsupported by PouchDB. Please follow up if you need more information.

Why expected route does not add item to models collection using sails.js blueprint API

Quick question for anyone that can help relating to adding an item to a models collection. (eg: Adding a tag to a blog post. Many to Many relationship) Doing this through a REST API call with default blueprints.
This works: http://host/blogpost/1/tag/add/2
however I would expect this to work: http://host/blogpost/1/tag/2
Instead it gives a 404 not found.
Thanks
Spencer
OK, thanks to #japel in the sails chat room for pointing out that there is no route for the second option. In fact now that I think about it, how else would the blueprint know if I want to add or remove an item without specifying the keyword, although perhaps changing from a POST to a DELETE could work. The comments in the docs for the blueprint API add method are somewhat misleading: http://sailsjs.org/documentation/reference/blueprint-api/add-to
For now I can live with specifying the action in the route.

How to search by id in Mockable.io?

I created a mock service using mockable.io.
For example:
Putting this in the url works:
http://demo#####.mockable.io/items
But if I filter it with:
http://demo#####.mockable.io/items?pid=5
It doesn't work as it should, it shows all the data instead of filtering them.
Can anyone tell me what I'm doing wrong please?
Mockable is in beta and I suspect they haven't sorted all the kinks out yet, I have the same problem when using it. An alternative is Sandbox - you can script mock service behaviour and can handle query parameters any way you like (disclaimer: I'm a founder)
I just tested your scenario and it works in my space.
Maybe you inverted the responses between the 2 mocks ?
You should send a support request to the mockable.io team. They are very active and will help you.
I solved it using filter.
Example: /blogs?filter=blog1
Documentation link: https://www.mockapi.io/docs
SEARCHING & FILTERING
Add query params to GET request:
/blogs?search=blog1
/blogs?filter=blog1
/blogs?title=cool%20blog

Displaying fancy routes in cloudmade based service

I look for a way to display a route in a fancy way using the Cloudmade service.
Currently, I can see computed routes like on this tutorial http://developers.cloudmade.com/projects/web-maps-lite/examples/routing, but I look for a fancier way to do it -- without A and B tags, and with colors, etc.
Is this possible ?
Thanks for your help
Rob
Currently this is not possible unfortunately, the only way to do this is to use the NavEngine API directly and process the JSON responses manually. But we will think about making the CM.Directions class more configurable in future releases, thanks!

Categories

Resources